How to use the asn1js.BmpString 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 DefinitelyTyped / DefinitelyTyped / types / pkijs / pkijs-tests.ts View on Github external
certSimpl.serialNumber = new asn1js.Integer({ value: 1 });
    certSimpl.issuer.typesAndValues.push(new AttributeTypeAndValue({
        type: "2.5.4.6", // Country name
        value: new asn1js.PrintableString({ value: "RU" })
    }));
    certSimpl.issuer.typesAndValues.push(new AttributeTypeAndValue({
        type: "2.5.4.3", // Common name
        value: new asn1js.BmpString({ value: "Test" })
    }));
    certSimpl.subject.typesAndValues.push(new AttributeTypeAndValue({
        type: "2.5.4.6", // Country name
        value: new asn1js.PrintableString({ value: "RU" })
    }));
    certSimpl.subject.typesAndValues.push(new AttributeTypeAndValue({
        type: "2.5.4.3", // Common name
        value: new asn1js.BmpString({ value: "Test" })
    }));

    certSimpl.notBefore.value = new Date(2016, 1, 1);
    certSimpl.notAfter.value = new Date(2019, 1, 1);

    certSimpl.extensions = []; // Extensions are not a part of certificate by default, it's an optional array

    // region "KeyUsage" extension
    const bitArray = new ArrayBuffer(1);
    const bitView = new Uint8Array(bitArray);

    bitView[0] = bitView[0] | 0x02; // Key usage "cRLSign" flag
    // bitView[0] = bitView[0] | 0x04; // Key usage "keyCertSign" flag

    const keyUsage = new asn1js.BitString({ valueHex: bitArray });
github PeculiarVentures / PKI.js / examples / HowToEncryptCMSviaCertificate / es6.js View on Github external
certificate.serialNumber = new asn1js.Integer({ value: 1 });
	certificate.issuer.typesAndValues.push(new AttributeTypeAndValue({
		type: "2.5.4.6", // Country name
		value: new asn1js.PrintableString({ value: "RU" })
	}));
	certificate.issuer.typesAndValues.push(new AttributeTypeAndValue({
		type: "2.5.4.3", // Common name
		value: new asn1js.BmpString({ value: "Test" })
	}));
	certificate.subject.typesAndValues.push(new AttributeTypeAndValue({
		type: "2.5.4.6", // Country name
		value: new asn1js.PrintableString({ value: "RU" })
	}));
	certificate.subject.typesAndValues.push(new AttributeTypeAndValue({
		type: "2.5.4.3", // Common name
		value: new asn1js.BmpString({ value: "Test" })
	}));
	
	certificate.notBefore.value = new Date(2016, 1, 1);
	certificate.notAfter.value = new Date(2019, 1, 1);
	
	certificate.extensions = []; // Extensions are not a part of certificate by default, it's an optional array
	
	//region "BasicConstraints" extension
	const basicConstr = new BasicConstraints({
		cA: true,
		pathLenConstraint: 3
	});
	
	certificate.extensions.push(new Extension({
		extnID: "2.5.29.19",
		critical: true,
github PeculiarVentures / CAdES.js / src / DirectoryString.js View on Github external
fromSchema(schema)
	{
		//region Check the schema is valid
		const asn1 = asn1js.compareSchema(schema,
			schema,
			new asn1js.Choice({
				value: [
					new asn1js.TeletexString({ name: "directoryString" }),
					new asn1js.PrintableString({ name: "directoryString" }),
					new asn1js.UniversalString({ name: "directoryString" }),
					new asn1js.Utf8String({ name: "directoryString" }),
					new asn1js.BmpString({ name: "directoryString" })
				]
			})
		);
		
		if(asn1.verified === false)
			throw new Error("Object's schema was not verified against input data for DirectoryString");
		//endregion
		
		//region Get internal properties from parsed schema
		// noinspection JSUnresolvedVariable
		this.value = asn1.result.directoryString.valueBlock.value;
		
		// noinspection JSUnresolvedVariable
		switch(asn1.result.directoryString.idBlock.tagNumber)
		{
			case 20: // TELETEXSTRING
github PeculiarVentures / PKI.js / src / GeneralName.js View on Github external
})
							]
						}),
						new asn1js.Constructed({
							idBlock: {
								tagClass: 3, // CONTEXT-SPECIFIC
								tagNumber: 1 // [1]
							},
							value: [
								new asn1js.Choice({
									value: [
										new asn1js.TeletexString(),
										new asn1js.PrintableString(),
										new asn1js.UniversalString(),
										new asn1js.Utf8String(),
										new asn1js.BmpString()
									]
								})
							]
						})
					]
				}),
				new asn1js.Primitive({
					name: (names.blockName || ""),
					idBlock: {
						tagClass: 3, // CONTEXT-SPECIFIC
						tagNumber: 6 // [6]
					}
				}),
				new asn1js.Primitive({
					name: (names.blockName || ""),
					idBlock: {
github PeculiarVentures / CAdES.js / src / DirectoryString.js View on Github external
switch(this.type)
		{
			case 0: // TELETEXSTRING
				result = new asn1js.TeletexString({ value: this.value });
				break;
			case 1: // PRINTABLESTRING
				result = new asn1js.PrintableString({ value: this.value });
				break;
			case 2: // UNIVERSALSTRING
				result = new asn1js.UniversalString({ value: this.value });
				break;
			case 3: // UTF8STRING
				result = new asn1js.Utf8String({ value: this.value });
				break;
			case 4: // BMPSTRING
				result = new asn1js.BmpString({ value: this.value });
				break;
			default:
				throw new Error("Incorrectly initialized data for \"DirectoryString\" class");
		}
		//endregion
		
		//region Construct and return new ASN.1 schema for this object
		return result;
		//endregion
	}
	//**********************************************************************************
github PeculiarVentures / PKI.js / examples / CRLComplexExample / es6.js View on Github external
//endregion
	
	//region Put a static values
	const crlSimpl = new CertificateRevocationList();
	
	crlSimpl.version = 1;
	
	crlSimpl.issuer.typesAndValues.push(new AttributeTypeAndValue({
		type: "2.5.4.6", // Country name
		value: new asn1js.PrintableString({
			value: "RU"
		})
	}));
	crlSimpl.issuer.typesAndValues.push(new AttributeTypeAndValue({
		type: "2.5.4.3", // Common name
		value: new asn1js.BmpString({
			value: "Test"
		})
	}));
	
	crlSimpl.thisUpdate = new Time({
		type: 0,
		value: new Date()
	});
	
	const revokedCertificate = new RevokedCertificate({
		userCertificate: new asn1js.Integer({
			value: 999
		}),
		revocationDate: new Time({
			value: new Date()
		}),
github PeculiarVentures / PKI.js / examples / CertificateComplexExample / es6.js View on Github external
certificate.serialNumber = new asn1js.Integer({ value: 1 });
	certificate.issuer.typesAndValues.push(new AttributeTypeAndValue({
		type: "2.5.4.6", // Country name
		value: new asn1js.PrintableString({ value: "RU" })
	}));
	certificate.issuer.typesAndValues.push(new AttributeTypeAndValue({
		type: "2.5.4.3", // Common name
		value: new asn1js.BmpString({ value: "Test" })
	}));
	certificate.subject.typesAndValues.push(new AttributeTypeAndValue({
		type: "2.5.4.6", // Country name
		value: new asn1js.PrintableString({ value: "RU" })
	}));
	certificate.subject.typesAndValues.push(new AttributeTypeAndValue({
		type: "2.5.4.3", // Common name
		value: new asn1js.BmpString({ value: "Test" })
	}));
	
	certificate.notBefore.value = new Date(2019, 1, 1);
	certificate.notAfter.value = new Date(2022, 1, 1);
	
	certificate.extensions = []; // Extensions are not a part of certificate by default, it's an optional array
	
	//region "BasicConstraints" extension
	const basicConstr = new BasicConstraints({
		cA: true,
		pathLenConstraint: 3
	});
	
	certificate.extensions.push(new Extension({
		extnID: "2.5.29.19",
		critical: true,
github PeculiarVentures / PKI.js / examples / OCSPRequestComplexExample / es6.js View on Github external
//region Initial variables
	const ocspReqSimpl = new OCSPRequest();
	//endregion
	
	//region Put static variables
	ocspReqSimpl.tbsRequest.requestorName = new GeneralName({
		type: 4,
		value: new RelativeDistinguishedNames({
			typesAndValues: [
				new AttributeTypeAndValue({
					type: "2.5.4.6", // Country name
					value: new asn1js.PrintableString({ value: "RU" })
				}),
				new AttributeTypeAndValue({
					type: "2.5.4.3", // Common name
					value: new asn1js.BmpString({ value: "Test" })
				})
			]
		})
	});
	
	const fictionBuffer = new ArrayBuffer(4);
	const fictionView = new Uint8Array(fictionBuffer);
	fictionView[0] = 0x7F;
	fictionView[1] = 0x01;
	fictionView[2] = 0x02;
	fictionView[3] = 0x03;
	
	ocspReqSimpl.tbsRequest.requestList = [new Request({
		reqCert: new CertID({
			hashAlgorithm: new AlgorithmIdentifier({
				algorithmId: "1.3.14.3.2.26"
github PeculiarVentures / CAdES.js / src / NoticeReference.js View on Github external
toSchema()
	{
		//region Create array for output sequence
		const outputArray = [];
		
		switch(this._organizationType)
		{
			case 0:
				outputArray.push(new asn1js.VisibleString({ value: this.organization }));
				break;
			case 1:
				outputArray.push(new asn1js.BmpString({ value: this.organization }));
				break;
			case 2:
				outputArray.push(new asn1js.Utf8String({ value: this.organization }));
				break;
			default:
				throw new Error("Non-initialized \"organization\" value");
		}
		
		outputArray.push(new asn1js.Sequence({
			value: Array.from(this.noticeNumbers)
		}));
		//endregion
		
		//region Construct and return new ASN.1 schema for this object
		return (new asn1js.Sequence({
			value: outputArray
github PeculiarVentures / CAdES.js / src / SPUserNotice.js View on Github external
*/
		const names = getParametersValue(parameters, "names", {});
		
		return (new asn1js.Sequence({
			name: (names.blockName || ""),
			value: [
				NoticeReference.schema(names.sPUserNotice || {
					names: {
						blockName: "",
						optional: true
					}
				}),
				new asn1js.Choice({
					value: [
						new asn1js.VisibleString({ name: (names.explicitText || "") }),
						new asn1js.BmpString({ name: (names.explicitText || "") }),
						new asn1js.Utf8String({ name: (names.explicitText || "") })
					]
				})
			]
		}));
	}
	//**********************************************************************************

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 2 years ago

Package Health Score

79 / 100
Full package analysis