import * as asn1js from "asn1js"; import * as pvutils from "pvutils"; import { AttributeTypeAndValue, AttributeTypeAndValueJson } from "./AttributeTypeAndValue"; import { EMPTY_BUFFER, EMPTY_STRING } from "./constants"; import { AsnError } from "./errors"; import { PkiObject, PkiObjectParameters } from "./PkiObject"; import * as Schema from "./Schema";
export interface IRelativeDistinguishedNames { /** * Array of "type and value" objects
*/
typesAndValues: AttributeTypeAndValue[]; /** * Value of the RDN before decoding from schema
*/
valueBeforeDecode: ArrayBuffer;
}
export type RelativeDistinguishedNamesParameters = PkiObjectParameters & Partial<IRelativeDistinguishedNames>;
/** * Represents the RelativeDistinguishedNames structure described in [RFC5280](https://datatracker.ietf.org/doc/html/rfc5280)
*/
export class RelativeDistinguishedNames extends PkiObject implements IRelativeDistinguishedNames {
public typesAndValues!: AttributeTypeAndValue[]; public valueBeforeDecode!: ArrayBuffer;
/** * Initializes a new instance of the {@link RelativeDistinguishedNames} class * @param parameters Initialization parameters
*/
constructor(parameters: RelativeDistinguishedNamesParameters = {}) { 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 TYPE_AND_VALUES): AttributeTypeAndValue[]; publicstatic override defaultValues(memberName: typeof VALUE_BEFORE_DECODE): ArrayBuffer; publicstatic override defaultValues(memberName: string): any { switch (memberName) { case TYPE_AND_VALUES: return []; case VALUE_BEFORE_DECODE: return EMPTY_BUFFER; 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
*/ publicstatic compareWithDefault(memberName: string, memberValue: any): boolean { switch (memberName) { case TYPE_AND_VALUES: return (memberValue.length === 0); case VALUE_BEFORE_DECODE: return (memberValue.byteLength === 0); default: returnsuper.defaultValues(memberName);
}
}
// Get internal properties from parsed schema if (TYPE_AND_VALUES in asn1.result) {// Could be a case when there is no "types and values" this.typesAndValues = Array.from(asn1.result.typesAndValues, element => new AttributeTypeAndValue({ schema: element }));
}
this.valueBeforeDecode = (asn1.result.RDN as asn1js.BaseBlock).valueBeforeDecodeView.slice().buffer;
}
public toSchema(): asn1js.Sequence { if (this.valueBeforeDecode.byteLength === 0) // No stored encoded array, create "from scratch"
{ return (new asn1js.Sequence({
value: [new asn1js.Set({
value: Array.from(this.typesAndValues, o => o.toSchema())
} as any)]
} as any));
}
const asn1 = asn1js.fromBER(this.valueBeforeDecode);
AsnError.assert(asn1, "RelativeDistinguishedNames"); if (!(asn1.result instanceof asn1js.Sequence)) { thrownew Error("ASN.1 result should be SEQUENCE");
}
return asn1.result;
}
public toJSON(): RelativeDistinguishedNamesJson { return {
typesAndValues: Array.from(this.typesAndValues, o => o.toJSON())
};
}
/** * Compares two RDN values, or RDN with ArrayBuffer value * @param compareTo The value compare to current
*/ public isEqual(compareTo: unknown): boolean { if (compareTo instanceof RelativeDistinguishedNames) { if (this.typesAndValues.length !== compareTo.typesAndValues.length) returnfalse;
for (const [index, typeAndValue] of this.typesAndValues.entries()) { if (typeAndValue.isEqual(compareTo.typesAndValues[index]) === false) returnfalse;
}
returntrue;
}
if (compareTo instanceof ArrayBuffer) { return pvutils.isEqualBuffer(this.valueBeforeDecode, compareTo);
}
returnfalse;
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet am 2026-06-06)
¤
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.