Update json-schema version

This commit is contained in:
microshine 2019-01-25 15:48:21 +03:00
parent 1a2838c08e
commit 6872ff74e0
10 changed files with 14 additions and 14 deletions

View File

@ -38,7 +38,7 @@ export class AesCrypto {
switch (format.toLowerCase()) { switch (format.toLowerCase()) {
case "jwk": case "jwk":
key = JsonParser.fromJSON(keyData, AesCryptoKey); key = JsonParser.fromJSON(keyData, { targetSchema: AesCryptoKey });
break; break;
case "raw": case "raw":
key = new AesCryptoKey(); key = new AesCryptoKey();

View File

@ -33,7 +33,7 @@ export class DesCrypto {
switch (format.toLowerCase()) { switch (format.toLowerCase()) {
case "jwk": case "jwk":
key = JsonParser.fromJSON(keyData, DesCryptoKey); key = JsonParser.fromJSON(keyData, { targetSchema: DesCryptoKey });
break; break;
case "raw": case "raw":
key = new DesCryptoKey(); key = new DesCryptoKey();

View File

@ -120,10 +120,10 @@ export class EcCrypto {
case "jwk": case "jwk":
const jwk = keyData as JsonWebKey; const jwk = keyData as JsonWebKey;
if (jwk.d) { if (jwk.d) {
const asnKey = JsonParser.fromJSON(keyData, asn.EcPrivateKey); const asnKey = JsonParser.fromJSON(keyData, { targetSchema: asn.EcPrivateKey });
return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages); return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages);
} else { } else {
const asnKey = JsonParser.fromJSON(keyData, asn.EcPublicKey); const asnKey = JsonParser.fromJSON(keyData, { targetSchema: asn.EcPublicKey });
return this.importPublicKey(asnKey, algorithm, extractable, keyUsages); return this.importPublicKey(asnKey, algorithm, extractable, keyUsages);
} }
case "raw": { case "raw": {

View File

@ -38,7 +38,7 @@ export class EcPrivateKey extends AsymmetricKey implements IJsonConvertible {
keyInfo.privateKeyAlgorithm.parameters = AsnSerializer.serialize( keyInfo.privateKeyAlgorithm.parameters = AsnSerializer.serialize(
new ObjectIdentifier(getOidByNamedCurve(json.crv!)), new ObjectIdentifier(getOidByNamedCurve(json.crv!)),
); );
const key = JsonParser.fromJSON(json, asn.EcPrivateKey); const key = JsonParser.fromJSON(json, { targetSchema: asn.EcPrivateKey });
keyInfo.privateKey = AsnSerializer.serialize(key); keyInfo.privateKey = AsnSerializer.serialize(key);
this.data = Buffer.from(AsnSerializer.serialize(keyInfo)); this.data = Buffer.from(AsnSerializer.serialize(keyInfo));

View File

@ -29,7 +29,7 @@ export class EcPublicKey extends AsymmetricKey implements IJsonConvertible {
} }
public fromJSON(json: JsonWebKey) { public fromJSON(json: JsonWebKey) {
const key = JsonParser.fromJSON(json, asn.EcPublicKey); const key = JsonParser.fromJSON(json, { targetSchema: asn.EcPublicKey });
const keyInfo = new asn.PublicKeyInfo(); const keyInfo = new asn.PublicKeyInfo();
keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.10045.2.1"; keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.10045.2.1";

View File

@ -40,7 +40,7 @@ export class HmacProvider extends core.HmacProvider {
switch (format.toLowerCase()) { switch (format.toLowerCase()) {
case "jwk": case "jwk":
key = JsonParser.fromJSON(keyData, HmacCryptoKey); key = JsonParser.fromJSON(keyData, { targetSchema: HmacCryptoKey });
break; break;
case "raw": case "raw":
key = new HmacCryptoKey(); key = new HmacCryptoKey();

View File

@ -77,10 +77,10 @@ export class RsaCrypto {
case "jwk": case "jwk":
const jwk = keyData as JsonWebKey; const jwk = keyData as JsonWebKey;
if (jwk.d) { if (jwk.d) {
const asnKey = JsonParser.fromJSON(keyData, asn.RsaPrivateKey); const asnKey = JsonParser.fromJSON(keyData, { targetSchema: asn.RsaPrivateKey });
return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages); return this.importPrivateKey(asnKey, algorithm, extractable, keyUsages);
} else { } else {
const asnKey = JsonParser.fromJSON(keyData, asn.RsaPublicKey); const asnKey = JsonParser.fromJSON(keyData, { targetSchema: asn.RsaPublicKey });
return this.importPublicKey(asnKey, algorithm, extractable, keyUsages); return this.importPublicKey(asnKey, algorithm, extractable, keyUsages);
} }
case "spki": { case "spki": {

View File

@ -27,7 +27,7 @@ export class RsaPrivateKey extends AsymmetricKey {
} }
public fromJSON(json: JsonWebKey) { public fromJSON(json: JsonWebKey) {
const key = JsonParser.fromJSON(json, asn.RsaPrivateKey); const key = JsonParser.fromJSON(json, { targetSchema: asn.RsaPrivateKey });
const keyInfo = new asn.PrivateKeyInfo(); const keyInfo = new asn.PrivateKeyInfo();
keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1"; keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";

View File

@ -27,7 +27,7 @@ export class RsaPublicKey extends AsymmetricKey {
} }
public fromJSON(json: JsonWebKey) { public fromJSON(json: JsonWebKey) {
const key = JsonParser.fromJSON(json, asn.RsaPublicKey); const key = JsonParser.fromJSON(json, { targetSchema: asn.RsaPublicKey });
const keyInfo = new asn.PublicKeyInfo(); const keyInfo = new asn.PublicKeyInfo();
keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1"; keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";

View File

@ -30,7 +30,7 @@ context("ASN", () => {
}); });
it("serialize", () => { it("serialize", () => {
const key = JsonParser.fromJSON(json, asn.RsaPrivateKey); const key = JsonParser.fromJSON(json, { targetSchema: asn.RsaPrivateKey });
const keyInfo = new asn.PrivateKeyInfo(); const keyInfo = new asn.PrivateKeyInfo();
keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1"; keyInfo.privateKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";
@ -60,7 +60,7 @@ context("ASN", () => {
}); });
it("serialize", () => { it("serialize", () => {
const key = JsonParser.fromJSON(json, asn.RsaPublicKey); const key = JsonParser.fromJSON(json, { targetSchema: asn.RsaPublicKey });
const keyInfo = new asn.PublicKeyInfo(); const keyInfo = new asn.PublicKeyInfo();
keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1"; keyInfo.publicKeyAlgorithm.algorithm = "1.2.840.113549.1.1.1";
@ -100,7 +100,7 @@ context("ASN", () => {
keyInfo.privateKeyAlgorithm.parameters = AsnSerializer.serialize( keyInfo.privateKeyAlgorithm.parameters = AsnSerializer.serialize(
new asn.ObjectIdentifier("1.2.840.10045.3.1.7"), new asn.ObjectIdentifier("1.2.840.10045.3.1.7"),
); );
const key = JsonParser.fromJSON(json, asn.EcPrivateKey); const key = JsonParser.fromJSON(json, { targetSchema: asn.EcPrivateKey });
keyInfo.privateKey = AsnSerializer.serialize(key); keyInfo.privateKey = AsnSerializer.serialize(key);
const asnKeyInfo = Buffer.from(AsnSerializer.serialize(keyInfo)); const asnKeyInfo = Buffer.from(AsnSerializer.serialize(keyInfo));