import * as asn1js from "asn1js"; import * as pvutils from "pvutils"; import { AlgorithmIdentifier, AlgorithmIdentifierJson, AlgorithmIdentifierSchema } from "./AlgorithmIdentifier"; import { SignedAndUnsignedAttributes, SignedAndUnsignedAttributesJson, SignedAndUnsignedAttributesSchema } from "./SignedAndUnsignedAttributes"; import { IssuerAndSerialNumber, IssuerAndSerialNumberSchema } from "./IssuerAndSerialNumber"; import * as Schema from "./Schema"; import { PkiObject, PkiObjectParameters } from "./PkiObject"; import { AsnError } from "./errors";
public version!: number; public sid: Schema.SchemaType; public digestAlgorithm!: AlgorithmIdentifier; public signedAttrs?: SignedAndUnsignedAttributes; public signatureAlgorithm!: AlgorithmIdentifier; public signature!: asn1js.OctetString; public unsignedAttrs?: SignedAndUnsignedAttributes;
/** * Initializes a new instance of the {@link SignerInfo} class * @param parameters Initialization parameters
*/
constructor(parameters: SignerInfoParameters = {}) { super();
if (parameters.schema) { this.fromSchema(parameters.schema);
}
}
/** * Returns default values for all class members * @param memberName String name for a class member * @returns Default value
*/ publicstatic override defaultValues(memberName: typeof VERSION): number; publicstatic override defaultValues(memberName: typeof SID): Schema.SchemaType; publicstatic override defaultValues(memberName: typeof DIGEST_ALGORITHM): AlgorithmIdentifier; publicstatic override defaultValues(memberName: typeof SIGNED_ATTRS): SignedAndUnsignedAttributes; publicstatic override defaultValues(memberName: typeof SIGNATURE_ALGORITHM): AlgorithmIdentifier; publicstatic override defaultValues(memberName: typeof SIGNATURE): asn1js.OctetString; publicstatic override defaultValues(memberName: typeof UNSIGNED_ATTRS): SignedAndUnsignedAttributes; publicstatic override defaultValues(memberName: string): any { switch (memberName) { case VERSION: return0; case SID: returnnew asn1js.Any(); case DIGEST_ALGORITHM: returnnew AlgorithmIdentifier(); case SIGNED_ATTRS: returnnew SignedAndUnsignedAttributes({ type: 0 }); case SIGNATURE_ALGORITHM: returnnew AlgorithmIdentifier(); case SIGNATURE: returnnew asn1js.OctetString(); case UNSIGNED_ATTRS: returnnew SignedAndUnsignedAttributes({ type: 1 }); default: returnsuper.defaultValues(memberName);
}
}
/** * Compare values with default values for all class members * @param memberName String name for a class member * @param memberValue Value to compare with default value
*/ publicstatic compareWithDefault(memberName: string, memberValue: any): boolean { switch (memberName) { case VERSION: return (SignerInfo.defaultValues(VERSION) === memberValue); case SID: return (memberValue instanceof asn1js.Any); case DIGEST_ALGORITHM: if ((memberValue instanceof AlgorithmIdentifier) === false) returnfalse;
return memberValue.isEqual(SignerInfo.defaultValues(DIGEST_ALGORITHM)); case SIGNED_ATTRS: return ((SignedAndUnsignedAttributes.compareWithDefault("type", memberValue.type))
&& (SignedAndUnsignedAttributes.compareWithDefault("attributes", memberValue.attributes))
&& (SignedAndUnsignedAttributes.compareWithDefault("encodedValue", memberValue.encodedValue))); case SIGNATURE_ALGORITHM: if ((memberValue instanceof AlgorithmIdentifier) === false) returnfalse;
return memberValue.isEqual(SignerInfo.defaultValues(SIGNATURE_ALGORITHM)); case SIGNATURE: case UNSIGNED_ATTRS: return ((SignedAndUnsignedAttributes.compareWithDefault("type", memberValue.type))
&& (SignedAndUnsignedAttributes.compareWithDefault("attributes", memberValue.attributes))
&& (SignedAndUnsignedAttributes.compareWithDefault("encodedValue", memberValue.encodedValue))); default: returnsuper.defaultValues(memberName);
}
}
public fromSchema(schema: Schema.SchemaType): void { // Clear input data first
pvutils.clearProps(schema, CLEAR_PROPS);
// Check the schema is valid const asn1 = asn1js.compareSchema(schema,
schema,
SignerInfo.schema()
);
AsnError.assertSchema(asn1, this.className);
// Get internal properties from parsed schema this.version = asn1.result[SIGNER_INFO_VERSION].valueBlock.valueDec;
const currentSid = asn1.result[SIGNER_INFO_SID]; if (currentSid.idBlock.tagClass === 1) this.sid = new IssuerAndSerialNumber({ schema: currentSid }); else this.sid = currentSid;
this.digestAlgorithm = new AlgorithmIdentifier({ schema: asn1.result[SIGNER_INFO_DIGEST_ALGORITHM] }); if (SIGNER_INFO_SIGNED_ATTRS in asn1.result) this.signedAttrs = new SignedAndUnsignedAttributes({ type: 0, schema: asn1.result[SIGNER_INFO_SIGNED_ATTRS] });
this.signatureAlgorithm = new AlgorithmIdentifier({ schema: asn1.result[SIGNER_INFO_SIGNATURE_ALGORITHM] }); this.signature = asn1.result[SIGNER_INFO_SIGNATURE]; if (SIGNER_INFO_UNSIGNED_ATTRS in asn1.result) this.unsignedAttrs = new SignedAndUnsignedAttributes({ type: 1, schema: asn1.result[SIGNER_INFO_UNSIGNED_ATTRS] });
}
public toSchema(): asn1js.Sequence { if (SignerInfo.compareWithDefault(SID, this.sid)) thrownew Error("Incorrectly initialized \"SignerInfo\" class");
//#region Create array for output sequence const outputArray = [];
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.