diff --git a/src/packet/public_key.js b/src/packet/public_key.js index d8f5a33e..cf2ff8ca 100644 --- a/src/packet/public_key.js +++ b/src/packet/public_key.js @@ -211,8 +211,11 @@ PublicKey.prototype.getBitSize = function () { * Fix custom types after cloning */ PublicKey.prototype.postCloneTypeFix = function() { - for (var i = 0; i < this.params.length; i++) { - this.params[i] = type_mpi.fromClone(this.params[i]); + const types = crypto.getPubKeyParamTypes(this.algorithm); + for (var i = 0; i < types.length; i++) { + const param = this.params[i]; + const cloneFn = crypto.getCloneFn(types[i]); + this.params[i] = cloneFn(param); } if (this.keyid) { this.keyid = type_keyid.fromClone(this.keyid); diff --git a/src/packet/secret_key.js b/src/packet/secret_key.js index a666175b..7d8c130f 100644 --- a/src/packet/secret_key.js +++ b/src/packet/secret_key.js @@ -38,6 +38,7 @@ import enums from '../enums.js'; import util from '../util.js'; import crypto from '../crypto'; import type_s2k from '../type/s2k.js'; +import type_keyid from '../type/keyid.js'; /** * @constructor @@ -291,3 +292,18 @@ SecretKey.prototype.clearPrivateParams = function () { this.params = this.params.slice(0, crypto.getPubKeyParamTypes(this.algorithm).length); this.isDecrypted = false; }; + +/** + * Fix custom types after cloning + */ + SecretKey.prototype.postCloneTypeFix = function() { + const types = crypto.getPubKeyParamTypes(this.algorithm).concat(crypto.getPrivKeyParamTypes(this.algorithm)); + for (var i = 0; i < this.params.length; i++) { + const param = this.params[i]; + const cloneFn = crypto.getCloneFn(types[i]); + this.params[i] = cloneFn(param); + } + if (this.keyid) { + this.keyid = type_keyid.fromClone(this.keyid); + } +}; diff --git a/src/type/kdf_params.js b/src/type/kdf_params.js index 4720c280..b5c8545b 100644 --- a/src/type/kdf_params.js +++ b/src/type/kdf_params.js @@ -59,3 +59,7 @@ KDFParams.prototype.read = function (input) { KDFParams.prototype.write = function () { return new Uint8Array([3, 1, this.hash, this.cipher]); }; + +KDFParams.fromClone = function (clone) { + return new KDFParams(clone.hash, clone.cipher); +}; \ No newline at end of file diff --git a/src/type/mpi.js b/src/type/mpi.js index 11e50504..cf5450f6 100644 --- a/src/type/mpi.js +++ b/src/type/mpi.js @@ -77,7 +77,6 @@ MPI.prototype.read = function (bytes) { // TODO: Verification of this size method! This size calculation as // specified above is not applicable in JavaScript var bytelen = Math.ceil(bits / 8); - var raw = util.Uint8Array2str(bytes.subarray(2, 2 + bytelen)); this.fromBytes(raw); diff --git a/src/type/oid.js b/src/type/oid.js index c4253889..e6cbad0b 100644 --- a/src/type/oid.js +++ b/src/type/oid.js @@ -67,3 +67,8 @@ OID.prototype.write = function () { return util.str2Uint8Array( String.fromCharCode(this.oid.length)+this.oid); }; + +OID.fromClone = function (clone) { + var oid = new OID(clone.oid); + return oid; +};