How to use the asn1js.GeneralizedTime function in asn1js

To help you get started, we’ve selected a few asn1js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github PeculiarVentures / CAdES.js / examples / CAdESComplexExample / es6.js View on Github external
sequence = sequence.then(result =>
	{
		tspKey = result;
		
		// #region Prepare buffer with combined "messageImprint" and "genTime"
		const asn1GenTime = new asn1js.GeneralizedTime({ valueDate: genTime });
		const buffer = utilConcatBuf(request.messageImprint.toSchema().toBER(false), asn1GenTime.toBER(false));
		// #endregion
		
		return crypto.digest({ name: "SHA-1" }, buffer);
	});
github PeculiarVentures / PKI.js / src / SingleResponse.js View on Github external
},
									value: [new asn1js.Enumerated()]
								})
							]
						}),
						new asn1js.Primitive({
							name: (names.certStatus || ""),
							idBlock: {
								tagClass: 3, // CONTEXT-SPECIFIC
								tagNumber: 2 // [2]
							},
							lenBlock: { length: 1 }
						}) // IMPLICIT NULL (no "valueBlock")
					]
				}),
				new asn1js.GeneralizedTime({ name: (names.thisUpdate || "") }),
				new asn1js.Constructed({
					optional: true,
					idBlock: {
						tagClass: 3, // CONTEXT-SPECIFIC
						tagNumber: 0 // [0]
					},
					value: [new asn1js.GeneralizedTime({ name: (names.nextUpdate || "") })]
				}),
				new asn1js.Constructed({
					optional: true,
					idBlock: {
						tagClass: 3, // CONTEXT-SPECIFIC
						tagNumber: 1 // [1]
					},
					value: [Extensions.schema(names.singleExtensions || {})]
				}) // EXPLICIT SEQUENCE value
github PeculiarVentures / PKI.js / src / PrivateKeyUsagePeriod.js View on Github external
toSchema()
	{
		//region Create array for output sequence
		const outputArray = [];
		
		if("notBefore" in this)
		{
			outputArray.push(new asn1js.Primitive({
				idBlock: {
					tagClass: 3, // CONTEXT-SPECIFIC
					tagNumber: 0 // [0]
				},
				valueHex: (new asn1js.GeneralizedTime({ valueDate: this.notBefore })).valueBlock.valueHex
			}));
		}
		
		if("notAfter" in this)
		{
			outputArray.push(new asn1js.Primitive({
				idBlock: {
					tagClass: 3, // CONTEXT-SPECIFIC
					tagNumber: 1 // [1]
				},
				valueHex: (new asn1js.GeneralizedTime({ valueDate: this.notAfter })).valueBlock.valueHex
			}));
		}
		//endregion
		
		//region Construct and return new ASN.1 schema for this object
github PeculiarVentures / PKI.js / src / ResponseData.js View on Github external
names: {
									blockName: "ResponseData.byName"
								}
							})]
						}),
						new asn1js.Constructed({
							name: (names.responderID || "ResponseData.responderID"),
							idBlock: {
								tagClass: 3, // CONTEXT-SPECIFIC
								tagNumber: 2 // [2]
							},
							value: [new asn1js.OctetString({ name: (names.ResponseDataByKey || "ResponseData.byKey") })]
						})
					]
				}),
				new asn1js.GeneralizedTime({ name: (names.producedAt || "ResponseData.producedAt") }),
				new asn1js.Sequence({
					value: [
						new asn1js.Repeated({
							name: "ResponseData.responses",
							value: SingleResponse.schema(names.response || {})
						})
					]
				}),
				new asn1js.Constructed({
					optional: true,
					idBlock: {
						tagClass: 3, // CONTEXT-SPECIFIC
						tagNumber: 1 // [1]
					},
					value: [Extensions.schema(names.extensions || {
						names: {
github PeculiarVentures / PKI.js / src / TSTInfo.js View on Github external
* @property {string} [extensions]
		 */
		const names = getParametersValue(parameters, "names", {});
		
		return (new asn1js.Sequence({
			name: (names.blockName || "TSTInfo"),
			value: [
				new asn1js.Integer({ name: (names.version || "TSTInfo.version") }),
				new asn1js.ObjectIdentifier({ name: (names.policy || "TSTInfo.policy") }),
				MessageImprint.schema(names.messageImprint || {
					names: {
						blockName: "TSTInfo.messageImprint"
					}
				}),
				new asn1js.Integer({ name: (names.serialNumber || "TSTInfo.serialNumber") }),
				new asn1js.GeneralizedTime({ name: (names.genTime || "TSTInfo.genTime") }),
				Accuracy.schema(names.accuracy || {
					names: {
						blockName: "TSTInfo.accuracy"
					}
				}),
				new asn1js.Boolean({
					name: (names.ordering || "TSTInfo.ordering"),
					optional: true
				}),
				new asn1js.Integer({
					name: (names.nonce || "TSTInfo.nonce"),
					optional: true
				}),
				new asn1js.Constructed({
					optional: true,
					idBlock: {
github PeculiarVentures / PKI.js / src / AttributeCertificateV1.js View on Github external
static schema(parameters = {})
	{
		/**
		 * @type {Object}
		 * @property {string} [blockName]
		 * @property {string} [notBeforeTime]
		 * @property {string} [notAfterTime]
		 */
		const names = getParametersValue(parameters, "names", {});
		
		return (new asn1js.Sequence({
			name: (names.blockName || ""),
			value: [
				new asn1js.GeneralizedTime({ name: (names.notBeforeTime || "") }),
				new asn1js.GeneralizedTime({ name: (names.notAfterTime || "") })
			]
		}));
	}
	//**********************************************************************************
github PeculiarVentures / PKI.js / src / AttributeCertificateV1.js View on Github external
toSchema()
	{
		//region Construct and return new ASN.1 schema for this object
		return (new asn1js.Sequence({
			value: [
				new asn1js.GeneralizedTime({ valueDate: this.notBeforeTime }),
				new asn1js.GeneralizedTime({ valueDate: this.notAfterTime }),
			]
		}));
		//endregion
	}
	//**********************************************************************************
github PeculiarVentures / PKI.js / src / PrivateKeyUsagePeriod.js View on Github external
PrivateKeyUsagePeriod.schema({
				names: {
					notBefore: "notBefore",
					notAfter: "notAfter"
				}
			})
		);

		if(asn1.verified === false)
			throw new Error("Object's schema was not verified against input data for PrivateKeyUsagePeriod");
		//endregion

		//region Get internal properties from parsed schema
		if("notBefore" in asn1.result)
		{
			const localNotBefore = new asn1js.GeneralizedTime();
			localNotBefore.fromBuffer(asn1.result.notBefore.valueBlock.valueHex);
			this.notBefore = localNotBefore.toDate();
		}

		if("notAfter" in asn1.result)
		{
			const localNotAfter = new asn1js.GeneralizedTime({ valueHex: asn1.result.notAfter.valueBlock.valueHex });
			localNotAfter.fromBuffer(asn1.result.notAfter.valueBlock.valueHex);
			this.notAfter = localNotAfter.toDate();
		}
		//endregion
	}
	//**********************************************************************************
github PeculiarVentures / PKI.js / src / Time.js View on Github external
static schema(parameters = {}, optional = false)
	{
		/**
		 * @type {Object}
		 * @property {string} [blockName]
		 * @property {string} [utcTimeName] Name for "utcTimeName" choice
		 * @property {string} [generalTimeName] Name for "generalTimeName" choice
		 */
		const names = getParametersValue(parameters, "names", {});

		return (new asn1js.Choice({
			optional,
			value: [
				new asn1js.UTCTime({ name: (names.utcTimeName || "") }),
				new asn1js.GeneralizedTime({ name: (names.generalTimeName || "") })
			]
		}));
	}
	//**********************************************************************************
github PeculiarVentures / PKI.js / src / KEKIdentifier.js View on Github external
static defaultValues(memberName)
	{
		switch(memberName)
		{
			case "keyIdentifier":
				return new asn1js.OctetString();
			case "date":
				return new asn1js.GeneralizedTime();
			case "other":
				return new OtherKeyAttribute();
			default:
				throw new Error(`Invalid member name for KEKIdentifier class: ${memberName}`);
		}
	}
	//**********************************************************************************

asn1js

asn1js is a pure JavaScript library implementing this standard. ASN.1 is the basis of all X.509 related data structures and numerous other protocols used on the web

BSD-3-Clause
Latest version published 3 years ago

Package Health Score

79 / 100
Full package analysis