Skip to content

Commit

Permalink
use same PublicKeyInfoValidator for ED25519
Browse files Browse the repository at this point in the history
  • Loading branch information
hamano committed Jul 8, 2022
1 parent 24094bb commit d6a5043
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 54 deletions.
53 changes: 2 additions & 51 deletions lib/asn1-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,56 +68,7 @@ exports.publicKeyInfoValidator = {
tagClass: asn1.Class.UNIVERSAL,
type: asn1.Type.BITSTRING,
constructed: false,
captureAsn1: 'subjectPublicKey',
captureBitStringValue: 'subjectPublicKeyRaw'
captureAsn1: 'subjectPublicKey', // used by RSA
captureBitStringValue: 'subjectPublicKeyRaw', // used by ECDSA and ED25519
}]
};

// obsolute: use publicKeyInfoValidator
exports.publicKeyValidator = {
name: 'SubjectPublicKeyInfo',
tagClass: asn1.Class.UNIVERSAL,
type: asn1.Type.SEQUENCE,
constructed: true,
captureAsn1: 'subjectPublicKeyInfo',
value: [{
name: 'SubjectPublicKeyInfo.AlgorithmIdentifier',
tagClass: asn1.Class.UNIVERSAL,
type: asn1.Type.SEQUENCE,
constructed: true,
value: [{
name: 'AlgorithmIdentifier.algorithm',
tagClass: asn1.Class.UNIVERSAL,
type: asn1.Type.OID,
constructed: false,
capture: 'publicKeyOid'
}]
},
// capture group for ed25519PublicKey
{
tagClass: asn1.Class.UNIVERSAL,
type: asn1.Type.BITSTRING,
constructed: false,
composed: true,
captureBitStringValue: 'ed25519PublicKey'
}
// FIXME: this is capture group for rsaPublicKey, use it in this API or
// discard?
/* {
// subjectPublicKey
name: 'SubjectPublicKeyInfo.subjectPublicKey',
tagClass: asn1.Class.UNIVERSAL,
type: asn1.Type.BITSTRING,
constructed: false,
value: [{
// RSAPublicKey
name: 'SubjectPublicKeyInfo.subjectPublicKey.RSAPublicKey',
tagClass: asn1.Class.UNIVERSAL,
type: asn1.Type.SEQUENCE,
constructed: true,
optional: true,
captureAsn1: 'rsaPublicKey'
}]
} */
]
};
1 change: 0 additions & 1 deletion lib/ecdsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ ECPublicKey.fromAsn1 = function(obj) {
error.errors = errors;
throw error;
}

var publicKey = capture.subjectPublicKeyRaw;
var params = capture.parameters;
var curve;
Expand Down
4 changes: 2 additions & 2 deletions lib/ed25519.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ ed25519.publicKeyFromAsn1 = function(obj) {
// get SubjectPublicKeyInfo
var capture = {};
var errors = [];
var valid = forge.asn1.validate(obj, publicKeyValidator, capture, errors);
var valid = forge.asn1.validate(obj, publicKeyInfoValidator, capture, errors);
if(!valid) {
var error = new Error('Invalid Key.');
error.errors = errors;
Expand All @@ -126,7 +126,7 @@ ed25519.publicKeyFromAsn1 = function(obj) {
throw new Error('Invalid OID "' + oid + '"; OID must be "' +
ed25519Oid + '".');
}
var publicKeyBytes = capture.ed25519PublicKey;
var publicKeyBytes = capture.ed25519PublicKeyRaw;
if(publicKeyBytes.length !== ed25519.constants.PUBLIC_KEY_BYTE_LENGTH) {
throw new Error('Key length is invalid.');
}
Expand Down

0 comments on commit d6a5043

Please sign in to comment.