-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
116 changed files
with
49,517 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
import * as asn1js from "asn1js"; | ||
import { getParametersValue, clearProps } from "pvutils"; | ||
import GeneralName from "./GeneralName.js"; | ||
//************************************************************************************** | ||
/** | ||
* Class from RFC5280 | ||
*/ | ||
export default class AccessDescription | ||
{ | ||
//********************************************************************************** | ||
/** | ||
* Constructor for AccessDescription class | ||
* @param {Object} [parameters={}] | ||
* @param {Object} [parameters.schema] asn1js parsed value to initialize the class from | ||
*/ | ||
constructor(parameters = {}) | ||
{ | ||
//region Internal properties of the object | ||
/** | ||
* @type {string} | ||
* @desc The type and format of the information are specified by the accessMethod field. This profile defines two accessMethod OIDs: id-ad-caIssuers and id-ad-ocsp | ||
*/ | ||
this.accessMethod = getParametersValue(parameters, "accessMethod", AccessDescription.defaultValues("accessMethod")); | ||
/** | ||
* @type {GeneralName} | ||
* @desc The accessLocation field specifies the location of the information | ||
*/ | ||
this.accessLocation = getParametersValue(parameters, "accessLocation", AccessDescription.defaultValues("accessLocation")); | ||
//endregion | ||
|
||
//region If input argument array contains "schema" for this object | ||
if("schema" in parameters) | ||
this.fromSchema(parameters.schema); | ||
//endregion | ||
} | ||
//********************************************************************************** | ||
/** | ||
* Return default values for all class members | ||
* @param {string} memberName String name for a class member | ||
*/ | ||
static defaultValues(memberName) | ||
{ | ||
switch(memberName) | ||
{ | ||
case "accessMethod": | ||
return ""; | ||
case "accessLocation": | ||
return new GeneralName(); | ||
default: | ||
throw new Error(`Invalid member name for AccessDescription class: ${memberName}`); | ||
} | ||
} | ||
//********************************************************************************** | ||
/** | ||
* Return value of pre-defined ASN.1 schema for current class | ||
* | ||
* ASN.1 schema: | ||
* ```asn1 | ||
* AccessDescription ::= SEQUENCE { | ||
* accessMethod OBJECT IDENTIFIER, | ||
* accessLocation GeneralName } | ||
* ``` | ||
* | ||
* @param {Object} parameters Input parameters for the schema | ||
* @returns {Object} asn1js schema object | ||
*/ | ||
static schema(parameters = {}) | ||
{ | ||
/** | ||
* @type {Object} | ||
* @property {string} [blockName] | ||
* @property {string} [accessMethod] | ||
* @property {string} [accessLocation] | ||
*/ | ||
const names = getParametersValue(parameters, "names", {}); | ||
|
||
return (new asn1js.Sequence({ | ||
name: (names.blockName || ""), | ||
value: [ | ||
new asn1js.ObjectIdentifier({ name: (names.accessMethod || "") }), | ||
GeneralName.schema(names.accessLocation || {}) | ||
] | ||
})); | ||
} | ||
//********************************************************************************** | ||
/** | ||
* Convert parsed asn1js object into current class | ||
* @param {!Object} schema | ||
*/ | ||
fromSchema(schema) | ||
{ | ||
//region Clear input data first | ||
clearProps(schema, [ | ||
"accessMethod", | ||
"accessLocation" | ||
]); | ||
//endregion | ||
|
||
//region Check the schema is valid | ||
const asn1 = asn1js.compareSchema(schema, | ||
schema, | ||
AccessDescription.schema({ | ||
names: { | ||
accessMethod: "accessMethod", | ||
accessLocation: { | ||
names: { | ||
blockName: "accessLocation" | ||
} | ||
} | ||
} | ||
}) | ||
); | ||
|
||
if(asn1.verified === false) | ||
throw new Error("Object's schema was not verified against input data for AccessDescription"); | ||
//endregion | ||
|
||
//region Get internal properties from parsed schema | ||
this.accessMethod = asn1.result.accessMethod.valueBlock.toString(); | ||
this.accessLocation = new GeneralName({ schema: asn1.result.accessLocation }); | ||
//endregion | ||
} | ||
//********************************************************************************** | ||
/** | ||
* Convert current object to asn1js object and set correct values | ||
* @returns {Object} asn1js object | ||
*/ | ||
toSchema() | ||
{ | ||
//region Construct and return new ASN.1 schema for this object | ||
return (new asn1js.Sequence({ | ||
value: [ | ||
new asn1js.ObjectIdentifier({ value: this.accessMethod }), | ||
this.accessLocation.toSchema() | ||
] | ||
})); | ||
//endregion | ||
} | ||
//********************************************************************************** | ||
/** | ||
* Convertion for the class to JSON object | ||
* @returns {Object} | ||
*/ | ||
toJSON() | ||
{ | ||
return { | ||
accessMethod: this.accessMethod, | ||
accessLocation: this.accessLocation.toJSON() | ||
}; | ||
} | ||
//********************************************************************************** | ||
} | ||
//************************************************************************************** |
Oops, something went wrong.