import * as asn1js from "asn1js"; import * as pvutils from "pvutils"; import { EMPTY_STRING } from "./constants"; import { AsnError } from "./errors"; import { PkiObject, PkiObjectParameters } from "./PkiObject"; import * as Schema from "./Schema";
export type AlgorithmIdentifierSchema = Schema.SchemaParameters<{
algorithmIdentifier?: string;
algorithmParams?: string;
}>;
/** * Represents the AlgorithmIdentifier structure described in [RFC5280](https://datatracker.ietf.org/doc/html/rfc5280)
*/
export class AlgorithmIdentifier extends PkiObject implements IAlgorithmIdentifier {
public algorithmId!: string; public algorithmParams?: any;
/** * Initializes a new instance of the {@link AlgorithmIdentifier} class * @param parameters Initialization parameters
*/
constructor(parameters: AlgorithmIdentifierParameters = {}) { super();
this.algorithmId = pvutils.getParametersValue(parameters, ALGORITHM_ID, AlgorithmIdentifier.defaultValues(ALGORITHM_ID)); if (ALGORITHM_PARAMS in parameters) { this.algorithmParams = pvutils.getParametersValue(parameters, ALGORITHM_PARAMS, AlgorithmIdentifier.defaultValues(ALGORITHM_PARAMS));
}
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 ALGORITHM_ID): string; publicstatic override defaultValues(memberName: typeof ALGORITHM_PARAMS): any; publicstatic override defaultValues(memberName: string): any { switch (memberName) { case ALGORITHM_ID: return EMPTY_STRING; case ALGORITHM_PARAMS: returnnew asn1js.Any(); default: returnsuper.defaultValues(memberName);
}
}
/** * Compares values with default values for all class members * @param memberName String name for a class member * @param memberValue Value to compare with default value
*/ static compareWithDefault(memberName: string, memberValue: any): boolean { switch (memberName) { case ALGORITHM_ID: return (memberValue === EMPTY_STRING); case ALGORITHM_PARAMS: return (memberValue instanceof asn1js.Any); default: returnsuper.defaultValues(memberName);
}
}
// Get internal properties from parsed schema this.algorithmId = asn1.result.algorithm.valueBlock.toString(); if (PARAMS in asn1.result) { this.algorithmParams = asn1.result.params;
}
}
public toSchema(): asn1js.Sequence { // Create array for output sequence const outputArray = [];
outputArray.push(new asn1js.ObjectIdentifier({ value: this.algorithmId })); if (this.algorithmParams && !(this.algorithmParams instanceof asn1js.Any)) {
outputArray.push(this.algorithmParams);
}
// Construct and return new ASN.1 schema for this object return (new asn1js.Sequence({
value: outputArray
}));
}
/** * Checks that two "AlgorithmIdentifiers" are equal * @param algorithmIdentifier
*/ public isEqual(algorithmIdentifier: unknown): boolean { //#region Check input type if (!(algorithmIdentifier instanceof AlgorithmIdentifier)) { returnfalse;
} //#endregion
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.