clone processing

This commit is contained in:
Sanjana Rajan 2017-11-26 19:41:06 -08:00
parent 86e15dbd0a
commit 311d288bb7
5 changed files with 30 additions and 3 deletions

View File

@ -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);

View File

@ -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);
}
};

View File

@ -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);
};

View File

@ -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);

View File

@ -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;
};