clone processing
This commit is contained in:
parent
86e15dbd0a
commit
311d288bb7
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
};
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user