import { BigInteger } from "../jsbn/jsbn" ; import { YAHOO } from "./yahoo" ; fileOverview name author Kenji Urushima kenji.urushima gmail version since license /**
 * kjur's class library name space
 * <p>
 * This name space provides following name spaces:
 * <ul>
 * <li> KJUR . asn1 - ASN.1 primitive hexadecimal encoder</li>
 * <li> KJUR . asn1 . x509 - ASN.1 structure for X.509 certificate and CRL</li>
 * <li> KJUR . crypto - Java Cryptographic Extension(JCE) style MessageDigest/Signature
 * class and utilities</li>
 * </ul>
 * </p>
 * NOTE: Please ignore method summary and document of this namespace. This caused by a bug of jsdoc2.
 *  name namespace export var KJUR = { } ; /**
 * kjur's ASN.1 class library name space
 * <p>
 * This is ITU-T X.690 ASN.1 DER encoder class library and
 * class structure and methods is very similar to
 * org.bouncycastle.asn1 package of
 * well known BouncyCaslte Cryptography Library.
 * <h4>PROVIDING ASN.1 PRIMITIVES</h4>
 * Here are ASN.1 DER primitive classes.
 * <ul>
 * <li>0x01  KJUR . asn1 . DERBoolean </li>
 * <li>0x02  KJUR . asn1 . DERInteger </li>
 * <li>0x03  KJUR . asn1 . DERBitString </li>
 * <li>0x04  KJUR . asn1 . DEROctetString </li>
 * <li>0x05  KJUR . asn1 . DERNull </li>
 * <li>0x06  KJUR . asn1 . DERObjectIdentifier </li>
 * <li>0x0a  KJUR . asn1 . DEREnumerated </li>
 * <li>0x0c  KJUR . asn1 . DERUTF8String </li>
 * <li>0x12  KJUR . asn1 . DERNumericString </li>
 * <li>0x13  KJUR . asn1 . DERPrintableString </li>
 * <li>0x14  KJUR . asn1 . DERTeletexString </li>
 * <li>0x16  KJUR . asn1 . DERIA5String </li>
 * <li>0x17  KJUR . asn1 . DERUTCTime </li>
 * <li>0x18  KJUR . asn1 . DERGeneralizedTime </li>
 * <li>0x30  KJUR . asn1 . DERSequence </li>
 * <li>0x31  KJUR . asn1 . DERSet </li>
 * </ul>
 * <h4>OTHER ASN.1 CLASSES</h4>
 * <ul>
 * <li> KJUR . asn1 . ASN1Object </li>
 * <li> KJUR . asn1 . DERAbstractString </li>
 * <li> KJUR . asn1 . DERAbstractTime </li>
 * <li> KJUR . asn1 . DERAbstractStructured </li>
 * <li> KJUR . asn1 . DERTaggedObject </li>
 * </ul>
 * <h4>SUB NAME SPACES</h4>
 * <ul>
 * <li> KJUR . asn1 . cades - CAdES long term signature format</li>
 * <li> KJUR . asn1 . cms - Cryptographic Message Syntax</li>
 * <li> KJUR . asn1 . csr - Certificate Signing Request (CSR/PKCS#10)</li>
 * <li> KJUR . asn1 . tsp - RFC 3161 Timestamping Protocol Format</li>
 * <li> KJUR . asn1 . x509 - RFC 5280 X.509 certificate and CRL</li>
 * </ul>
 * </p>
 * NOTE: Please ignore method summary and document of this namespace.
 * This caused by a bug of jsdoc2.
 *  name namespace if ( typeof KJUR . asn1 == "undefined" || ! KJUR . asn1 ) KJUR . asn1 = { } ; name class since KJUR . asn1 . ASN1Util = new function ( ) { this . integerToByteHex = function ( i ) { var h = i . toString ( 16 ) ; if ( ( h . length % 2 ) == 1 ) h = '0' + h ; return h ; } ; this . bigIntToMinTwosComplementsHex = function ( bigIntegerValue ) { var h = bigIntegerValue . toString ( 16 ) ; if ( h . substr ( 0 , 1 ) != '-' ) { if ( h . length % 2 == 1 ) { h = '0' + h ; } else { if ( ! h . match ( /^[0-7]/ ) ) { h = '00' + h ; } } } else { var hPos = h . substr ( 1 ) ; var xorLen = hPos . length ; if ( xorLen % 2 == 1 ) { xorLen += 1 ; } else { if ( ! h . match ( /^[0-7]/ ) ) { xorLen += 2 ; } } var hMask = '' ; for ( var i = 0 ; i < xorLen ; i ++ ) { hMask += 'f' ; } var biMask = new BigInteger ( hMask , 16 ) ; var biNeg = biMask . xor ( bigIntegerValue ) . add ( BigInteger . ONE ) ; h = biNeg . toString ( 16 ) . replace ( /^-/ , '' ) ; } return h ; } ; name memberOf function param { String } dataHex param { String } pemHeader return { String } description example this . getPEMStringFromHex = function ( dataHex , pemHeader ) { return hextopem ( dataHex , pemHeader ) ; } ; name memberOf function param { Array } param return { KJUR . asn1 . ASN1Object } since description example this . newObject = function ( param ) { var _KJUR = KJUR , _KJUR_asn1 = _KJUR . asn1 , _DERBoolean = _KJUR_asn1 . DERBoolean , _DERInteger = _KJUR_asn1 . DERInteger , _DERBitString = _KJUR_asn1 . DERBitString , _DEROctetString = _KJUR_asn1 . DEROctetString , _DERNull = _KJUR_asn1 . DERNull , _DERObjectIdentifier = _KJUR_asn1 . DERObjectIdentifier , _DEREnumerated = _KJUR_asn1 . DEREnumerated , _DERUTF8String = _KJUR_asn1 . DERUTF8String , _DERNumericString = _KJUR_asn1 . DERNumericString , _DERPrintableString = _KJUR_asn1 . DERPrintableString , _DERTeletexString = _KJUR_asn1 . DERTeletexString , _DERIA5String = _KJUR_asn1 . DERIA5String , _DERUTCTime = _KJUR_asn1 . DERUTCTime , _DERGeneralizedTime = _KJUR_asn1 . DERGeneralizedTime , _DERSequence = _KJUR_asn1 . DERSequence , _DERSet = _KJUR_asn1 . DERSet , _DERTaggedObject = _KJUR_asn1 . DERTaggedObject , _newObject = _KJUR_asn1 . ASN1Util . newObject ; var keys = Object . keys ( param ) ; if ( keys . length != 1 ) throw "key of param shall be only one." ; var key = keys [ 0 ] ; if ( ":bool:int:bitstr:octstr:null:oid:enum:utf8str:numstr:prnstr:telstr:ia5str:utctime:gentime:seq:set:tag:" . indexOf ( ":" + key + ":" ) == - 1 ) throw "undefined key: " + key ; if ( key == "bool" ) return new _DERBoolean ( param [ key ] ) ; if ( key == "int" ) return new _DERInteger ( param [ key ] ) ; if ( key == "bitstr" ) return new _DERBitString ( param [ key ] ) ; if ( key == "octstr" ) return new _DEROctetString ( param [ key ] ) ; if ( key == "null" ) return new _DERNull ( param [ key ] ) ; if ( key == "oid" ) return new _DERObjectIdentifier ( param [ key ] ) ; if ( key == "enum" ) return new _DEREnumerated ( param [ key ] ) ; if ( key == "utf8str" ) return new _DERUTF8String ( param [ key ] ) ; if ( key == "numstr" ) return new _DERNumericString ( param [ key ] ) ; if ( key == "prnstr" ) return new _DERPrintableString ( param [ key ] ) ; if ( key == "telstr" ) return new _DERTeletexString ( param [ key ] ) ; if ( key == "ia5str" ) return new _DERIA5String ( param [ key ] ) ; if ( key == "utctime" ) return new _DERUTCTime ( param [ key ] ) ; if ( key == "gentime" ) return new _DERGeneralizedTime ( param [ key ] ) ; if ( key == "seq" ) { var paramList = param [ key ] ; var a = [ ] ; for ( var i = 0 ; i < paramList . length ; i ++ ) { var asn1Obj = _newObject ( paramList [ i ] ) ; a . push ( asn1Obj ) ; } return new _DERSequence ( { 'array' : a } ) ; } if ( key == "set" ) { var paramList = param [ key ] ; var a = [ ] ; for ( var i = 0 ; i < paramList . length ; i ++ ) { var asn1Obj = _newObject ( paramList [ i ] ) ; a . push ( asn1Obj ) ; } return new _DERSet ( { 'array' : a } ) ; } if ( key == "tag" ) { var tagParam = param [ key ] ; if ( Object . prototype . toString . call ( tagParam ) === '[object Array]' && tagParam . length == 3 ) { var obj = _newObject ( tagParam [ 2 ] ) ; return new _DERTaggedObject ( { tag : tagParam [ 0 ] , explicit : tagParam [ 1 ] , obj : obj } ) ; } else { var newParam = { } ; if ( tagParam . explicit !== undefined ) newParam . explicit = tagParam . explicit ; if ( tagParam . tag !== undefined ) newParam . tag = tagParam . tag ; if ( tagParam . obj === undefined ) throw "obj shall be specified for 'tag'." ; newParam . obj = _newObject ( tagParam . obj ) ; return new _DERTaggedObject ( newParam ) ; } } } ; name memberOf function param { Array } param return since description As for ASN.1 object representation of JSON object,
     * please see  newObject .
     *  example this . jsonToASN1HEX = function ( param ) { var asn1Obj = this . newObject ( param ) ; return asn1Obj . getEncodedHex ( ) ; } ; } ; name memberOf function param { String } hex return { String } since description example KJUR . asn1 . ASN1Util . oidHexToInt = function ( hex ) { var s = "" ; var i01 = parseInt ( hex . substr ( 0 , 2 ) , 16 ) ; var i0 = Math . floor ( i01 / 40 ) ; var i1 = i01 % 40 ; var s = i0 + "." + i1 ; var binbuf = "" ; for ( var i = 2 ; i < hex . length ; i += 2 ) { var value = parseInt ( hex . substr ( i , 2 ) , 16 ) ; var bin = ( "00000000" + value . toString ( 2 ) ) . slice ( - 8 ) ; binbuf = binbuf + bin . substr ( 1 , 7 ) ; if ( bin . substr ( 0 , 1 ) == "0" ) { var bi = new BigInteger ( binbuf , 2 ) ; s = s + "." + bi . toString ( 10 ) ; binbuf = "" ; } } ; return s ; } ; name memberOf function param { String } oidString return { String } since description example KJUR . asn1 . ASN1Util . oidIntToHex = function ( oidString ) { var itox = function ( i ) { var h = i . toString ( 16 ) ; if ( h . length == 1 ) h = '0' + h ; return h ; } ; var roidtox = function ( roid ) { var h = '' ; var bi = new BigInteger ( roid , 10 ) ; var b = bi . toString ( 2 ) ; var padLen = 7 - b . length % 7 ; if ( padLen == 7 ) padLen = 0 ; var bPad = '' ; for ( var i = 0 ; i < padLen ; i ++ ) bPad += '0' ; b = bPad + b ; for ( var i = 0 ; i < b . length - 1 ; i += 7 ) { var b8 = b . substr ( i , 7 ) ; if ( i != b . length - 7 ) b8 = '1' + b8 ; h += itox ( parseInt ( b8 , 2 ) ) ; } return h ; } ; if ( ! oidString . match ( /^[0-9.]+$/ ) ) { throw "malformed oid string: " + oidString ; } var h = '' ; var a = oidString . split ( '.' ) ; var i0 = parseInt ( a [ 0 ] ) * 40 + parseInt ( a [ 1 ] ) ; h += itox ( i0 ) ; a . splice ( 0 , 2 ) ; for ( var i = 0 ; i < a . length ; i ++ ) { h += roidtox ( a [ i ] ) ; } return h ; } ; name class property property property property property description KJUR . asn1 . ASN1Object = function ( ) { var isModified = true ; var hTLV = null ; var hT = '00' ; var hL = '00' ; var hV = '' ; name memberOf function return { String } this . getLengthHexFromValue = function ( ) { if ( typeof this . hV == "undefined" || this . hV == null ) { throw "this.hV is null or undefined." ; } if ( this . hV . length % 2 == 1 ) { throw "value hex must be even length: n=" + hV . length + ",v=" + this . hV ; } var n = this . hV . length / 2 ; var hN = n . toString ( 16 ) ; if ( hN . length % 2 == 1 ) { hN = "0" + hN ; } if ( n < 128 ) { return hN ; } else { var hNlen = hN . length / 2 ; if ( hNlen > 15 ) { throw "ASN.1 length too long to represent by 8x: n = " + n . toString ( 16 ) ; } var head = 128 + hNlen ; return head . toString ( 16 ) + hN ; } } ; name memberOf function return { String } this . getEncodedHex = function ( ) { if ( this . hTLV == null || this . isModified ) { this . hV = this . getFreshValueHex ( ) ; this . hL = this . getLengthHexFromValue ( ) ; this . hTLV = this . hT + this . hL + this . hV ; this . isModified = false ; } return this . hTLV ; } ; name memberOf function return { String } this . getValueHex = function ( ) { this . getEncodedHex ( ) ; return this . hV ; } ; this . getFreshValueHex = function ( ) { return '' ; } ; } ; name class param { Array } params property extends KJUR . asn1 . ASN1Object description KJUR . asn1 . DERAbstractString = function ( params ) { KJUR . asn1 . DERAbstractString . superclass . constructor . call ( this ) ; var s = null ; var hV = null ; name memberOf function return { String } this . getString = function ( ) { return this . s ; } ; name memberOf function param { String } newS this . setString = function ( newS ) { this . hTLV = null ; this . isModified = true ; this . s = newS ; this . hV = stohex ( this . s ) ; } ; name memberOf function param { String } newHexString this . setStringHex = function ( newHexString ) { this . hTLV = null ; this . isModified = true ; this . s = null ; this . hV = newHexString ; } ; this . getFreshValueHex = function ( ) { return this . hV ; } ; if ( typeof params != "undefined" ) { if ( typeof params == "string" ) { this . setString ( params ) ; } else if ( typeof params [ 'str' ] != "undefined" ) { this . setString ( params [ 'str' ] ) ; } else if ( typeof params [ 'hex' ] != "undefined" ) { this . setStringHex ( params [ 'hex' ] ) ; } } } ; YAHOO . lang . extend ( KJUR . asn1 . DERAbstractString , KJUR . asn1 . ASN1Object ) ; name class param { Array } params extends KJUR . asn1 . ASN1Object description see KJUR . asn1 . ASN1Object KJUR . asn1 . DERAbstractTime = function ( params ) { KJUR . asn1 . DERAbstractTime . superclass . constructor . call ( this ) ; var s = null ; var date = null ; this . localDateToUTC = function ( d ) { utc = d . getTime ( ) + ( d . getTimezoneOffset ( ) * 60000 ) ; var utcDate = new Date ( utc ) ; return utcDate ; } ; this . formatDate = function ( dateObject , type , withMillis ) { var pad = this . zeroPadding ; var d = this . localDateToUTC ( dateObject ) ; var year = String ( d . getFullYear ( ) ) ; if ( type == 'utc' ) year = year . substr ( 2 , 2 ) ; var month = pad ( String ( d . getMonth ( ) + 1 ) , 2 ) ; var day = pad ( String ( d . getDate ( ) ) , 2 ) ; var hour = pad ( String ( d . getHours ( ) ) , 2 ) ; var min = pad ( String ( d . getMinutes ( ) ) , 2 ) ; var sec = pad ( String ( d . getSeconds ( ) ) , 2 ) ; var s = year + month + day + hour + min + sec ; if ( withMillis === true ) { var millis = d . getMilliseconds ( ) ; if ( millis != 0 ) { var sMillis = pad ( String ( millis ) , 3 ) ; sMillis = sMillis . replace ( /[0]+$/ , "" ) ; s = s + "." + sMillis ; } } return s + "Z" ; } ; this . zeroPadding = function ( s , len ) { if ( s . length >= len ) return s ; return new Array ( len - s . length + 1 ) . join ( '0' ) + s ; } ; name memberOf function return { String } this . getString = function ( ) { return this . s ; } ; name memberOf function param { String } newS this . setString = function ( newS ) { this . hTLV = null ; this . isModified = true ; this . s = newS ; this . hV = stohex ( newS ) ; } ; name memberOf function param { Integer } year param { Integer } month param { Integer } day param { Integer } hour param { Integer } min param { Integer } sec this . setByDateValue = function ( year , month , day , hour , min , sec ) { var dateObject = new Date ( Date . UTC ( year , month - 1 , day , hour , min , sec , 0 ) ) ; this . setByDate ( dateObject ) ; } ; this . getFreshValueHex = function ( ) { return this . hV ; } ; } ; YAHOO . lang . extend ( KJUR . asn1 . DERAbstractTime , KJUR . asn1 . ASN1Object ) ; name class property extends KJUR . asn1 . ASN1Object description see KJUR . asn1 . ASN1Object KJUR . asn1 . DERAbstractStructured = function ( params ) { KJUR . asn1 . DERAbstractString . superclass . constructor . call ( this ) ; var asn1Array = null ; name memberOf function param { array } asn1ObjectArray this . setByASN1ObjectArray = function ( asn1ObjectArray ) { this . hTLV = null ; this . isModified = true ; this . asn1Array = asn1ObjectArray ; } ; name memberOf function param { ASN1Object } asn1Object this . appendASN1Object = function ( asn1Object ) { this . hTLV = null ; this . isModified = true ; this . asn1Array . push ( asn1Object ) ; } ; this . asn1Array = new Array ( ) ; if ( typeof params != "undefined" ) { if ( typeof params [ 'array' ] != "undefined" ) { this . asn1Array = params [ 'array' ] ; } } } ; YAHOO . lang . extend ( KJUR . asn1 . DERAbstractStructured , KJUR . asn1 . ASN1Object ) ; name class extends KJUR . asn1 . ASN1Object description see KJUR . asn1 . ASN1Object KJUR . asn1 . DERBoolean = function ( ) { KJUR . asn1 . DERBoolean . superclass . constructor . call ( this ) ; this . hT = "01" ; this . hTLV = "0101ff" ; } ; YAHOO . lang . extend ( KJUR . asn1 . DERBoolean , KJUR . asn1 . ASN1Object ) ; name class extends KJUR . asn1 . ASN1Object description KJUR . asn1 . DERInteger = function ( params ) { KJUR . asn1 . DERInteger . superclass . constructor . call ( this ) ; this . hT = "02" ; name memberOf function param { BigInteger } bigIntegerValue this . setByBigInteger = function ( bigIntegerValue ) { this . hTLV = null ; this . isModified = true ; this . hV = KJUR . asn1 . ASN1Util . bigIntToMinTwosComplementsHex ( bigIntegerValue ) ; } ; name memberOf function param { Integer } integer this . setByInteger = function ( intValue ) { var bi = new BigInteger ( String ( intValue ) , 10 ) ; this . setByBigInteger ( bi ) ; } ; name memberOf function param { String } hexadecimal description example this . setValueHex = function ( newHexString ) { this . hV = newHexString ; } ; this . getFreshValueHex = function ( ) { return this . hV ; } ; if ( typeof params != "undefined" ) { if ( typeof params [ 'bigint' ] != "undefined" ) { this . setByBigInteger ( params [ 'bigint' ] ) ; } else if ( typeof params [ 'int' ] != "undefined" ) { this . setByInteger ( params [ 'int' ] ) ; } else if ( typeof params == "number" ) { this . setByInteger ( params ) ; } else if ( typeof params [ 'hex' ] != "undefined" ) { this . setValueHex ( params [ 'hex' ] ) ; } } } ; YAHOO . lang . extend ( KJUR . asn1 . DERInteger , KJUR . asn1 . ASN1Object ) ; name class extends KJUR . asn1 . ASN1Object description <br/>
 * As for argument 'params' for constructor, you can specify one of
 * following properties:
 * <ul>
 * <li>bin - specify binary string (ex. '10111')</li>
 * <li>array - specify array of boolean (ex. [true,false,true,true])</li>
 * <li>hex - specify hexadecimal string of ASN.1 value(V) including unused bits</li>
 * <li>obj - specify  KJUR . asn1 . ASN1Util . newObject * argument for "BitString encapsulates" structure.</li>
 * </ul>
 * NOTE1: 'params' can be omitted.<br/>
 * NOTE2: 'obj' parameter have been supported since
 * asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25).<br/>
 *  example KJUR . asn1 . DERBitString = function ( params ) { if ( params !== undefined && typeof params . obj !== "undefined" ) { var o = KJUR . asn1 . ASN1Util . newObject ( params . obj ) ; params . hex = "00" + o . getEncodedHex ( ) ; } KJUR . asn1 . DERBitString . superclass . constructor . call ( this ) ; this . hT = "03" ; name memberOf function param { String } newHexStringIncludingUnusedBits this . setHexValueIncludingUnusedBits = function ( newHexStringIncludingUnusedBits ) { this . hTLV = null ; this . isModified = true ; this . hV = newHexStringIncludingUnusedBits ; } ; name memberOf function param { Integer } unusedBits param { String } hValue this . setUnusedBitsAndHexValue = function ( unusedBits , hValue ) { if ( unusedBits < 0 || 7 < unusedBits ) { throw "unused bits shall be from 0 to 7: u = " + unusedBits ; } var hUnusedBits = "0" + unusedBits ; this . hTLV = null ; this . isModified = true ; this . hV = hUnusedBits + hValue ; } ; name memberOf function param { String } binaryString description example this . setByBinaryString = function ( binaryString ) { binaryString = binaryString . replace ( /0+$/ , '' ) ; var unusedBits = 8 - binaryString . length % 8 ; if ( unusedBits == 8 ) unusedBits = 0 ; for ( var i = 0 ; i <= unusedBits ; i ++ ) { binaryString += '0' ; } var h = '' ; for ( var i = 0 ; i < binaryString . length - 1 ; i += 8 ) { var b = binaryString . substr ( i , 8 ) ; var x = parseInt ( b , 2 ) . toString ( 16 ) ; if ( x . length == 1 ) x = '0' + x ; h += x ; } this . hTLV = null ; this . isModified = true ; this . hV = '0' + unusedBits + h ; } ; name memberOf function param { array } booleanArray description example this . setByBooleanArray = function ( booleanArray ) { var s = '' ; for ( var i = 0 ; i < booleanArray . length ; i ++ ) { if ( booleanArray [ i ] == true ) { s += '1' ; } else { s += '0' ; } } this . setByBinaryString ( s ) ; } ; name memberOf function param { Integer } nLength return { array } description example this . newFalseArray = function ( nLength ) { var a = new Array ( nLength ) ; for ( var i = 0 ; i < nLength ; i ++ ) { a [ i ] = false ; } return a ; } ; this . getFreshValueHex = function ( ) { return this . hV ; } ; if ( typeof params != "undefined" ) { if ( typeof params == "string" && params . toLowerCase ( ) . match ( /^[0-9a-f]+$/ ) ) { this . setHexValueIncludingUnusedBits ( params ) ; } else if ( typeof params [ 'hex' ] != "undefined" ) { this . setHexValueIncludingUnusedBits ( params [ 'hex' ] ) ; } else if ( typeof params [ 'bin' ] != "undefined" ) { this . setByBinaryString ( params [ 'bin' ] ) ; } else if ( typeof params [ 'array' ] != "undefined" ) { this . setByBooleanArray ( params [ 'array' ] ) ; } } } ; YAHOO . lang . extend ( KJUR . asn1 . DERBitString , KJUR . asn1 . ASN1Object ) ; name class param { Array } params extends KJUR . asn1 . DERAbstractString description This class provides ASN.1 OctetString simple type.<br/>
 * Supported "params" attributes are:
 * <ul>
 * <li>str - to set a string as a value</li>
 * <li>hex - to set a hexadecimal string as a value</li>
 * <li>obj - to set a encapsulated ASN.1 value by JSON object
 * which is defined in  KJUR . asn1 . ASN1Util . newObject </li>
 * </ul>
 * NOTE: A parameter 'obj' have been supported
 * for "OCTET STRING, encapsulates" structure.
 * since asn1 1.0.11, jsrsasign 6.1.1 (2016-Sep-25).
 *  see KJUR . asn1 . DERAbstractString example KJUR . asn1 . DEROctetString = function ( params ) { if ( params !== undefined && typeof params . obj !== "undefined" ) { var o = KJUR . asn1 . ASN1Util . newObject ( params . obj ) ; params . hex = o . getEncodedHex ( ) ; } KJUR . asn1 . DEROctetString . superclass . constructor . call ( this , params ) ; this . hT = "04" ; } ; YAHOO . lang . extend ( KJUR . asn1 . DEROctetString , KJUR . asn1 . DERAbstractString ) ; name class extends KJUR . asn1 . ASN1Object description see KJUR . asn1 . ASN1Object KJUR . asn1 . DERNull = function ( ) { KJUR . asn1 . DERNull . superclass . constructor . call ( this ) ; this . hT = "05" ; this . hTLV = "0500" ; } ; YAHOO . lang . extend ( KJUR . asn1 . DERNull , KJUR . asn1 . ASN1Object ) ; name class param { Array } params extends KJUR . asn1 . ASN1Object description KJUR . asn1 . DERObjectIdentifier = function ( params ) { var itox = function ( i ) { var h = i . toString ( 16 ) ; if ( h . length == 1 ) h = '0' + h ; return h ; } ; var roidtox = function ( roid ) { var h = '' ; var bi = new BigInteger ( roid , 10 ) ; var b = bi . toString ( 2 ) ; var padLen = 7 - b . length % 7 ; if ( padLen == 7 ) padLen = 0 ; var bPad = '' ; for ( var i = 0 ; i < padLen ; i ++ ) bPad += '0' ; b = bPad + b ; for ( var i = 0 ; i < b . length - 1 ; i += 7 ) { var b8 = b . substr ( i , 7 ) ; if ( i != b . length - 7 ) b8 = '1' + b8 ; h += itox ( parseInt ( b8 , 2 ) ) ; } return h ; } ; KJUR . asn1 . DERObjectIdentifier . superclass . constructor . call ( this ) ; this . hT = "06" ; name memberOf function param { String } newHexString this . setValueHex = function ( newHexString ) { this . hTLV = null ; this . isModified = true ; this . s = null ; this . hV = newHexString ; } ; name memberOf function param { String } oidString example this . setValueOidString = function ( oidString ) { if ( ! oidString . match ( /^[0-9.]+$/ ) ) { throw "malformed oid string: " + oidString ; } var h = '' ; var a = oidString . split ( '.' ) ; var i0 = parseInt ( a [ 0 ] ) * 40 + parseInt ( a [ 1 ] ) ; h += itox ( i0 ) ; a . splice ( 0 , 2 ) ; for ( var i = 0 ; i < a . length ; i ++ ) { h += roidtox ( a [ i ] ) ; } this . hTLV = null ; this . isModified = true ; this . s = null ; this . hV = h ; } ; name memberOf function param { String } oidName since description example this . setValueName = function ( oidName ) { var oid = KJUR . asn1 . x509 . OID . name2oid ( oidName ) ; if ( oid !== '' ) { this . setValueOidString ( oid ) ; } else { throw "DERObjectIdentifier oidName undefined: " + oidName ; } } ; this . getFreshValueHex = function ( ) { return this . hV ; } ; if ( params !== undefined ) { if ( typeof params === "string" ) { if ( params . match ( /^[0-2].[0-9.]+$/ ) ) { this . setValueOidString ( params ) ; } else { this . setValueName ( params ) ; } } else if ( params . oid !== undefined ) { this . setValueOidString ( params . oid ) ; } else if ( params . hex !== undefined ) { this . setValueHex ( params . hex ) ; } else if ( params . name !== undefined ) { this . setValueName ( params . name ) ; } } } ; YAHOO . lang . extend ( KJUR . asn1 . DERObjectIdentifier , KJUR . asn1 . ASN1Object ) ; name class extends KJUR . asn1 . ASN1Object description example KJUR . asn1 . DEREnumerated = function ( params ) { KJUR . asn1 . DEREnumerated . superclass . constructor . call ( this ) ; this . hT = "0a" ; name memberOf function param { BigInteger } bigIntegerValue this . setByBigInteger = function ( bigIntegerValue ) { this . hTLV = null ; this . isModified = true ; this . hV = KJUR . asn1 . ASN1Util . bigIntToMinTwosComplementsHex ( bigIntegerValue ) ; } ; name memberOf function param { Integer } integer this . setByInteger = function ( intValue ) { var bi = new BigInteger ( String ( intValue ) , 10 ) ; this . setByBigInteger ( bi ) ; } ; name memberOf function param { String } hexadecimal description this . setValueHex = function ( newHexString ) { this . hV = newHexString ; } ; this . getFreshValueHex = function ( ) { return this . hV ; } ; if ( typeof params != "undefined" ) { if ( typeof params [ 'int' ] != "undefined" ) { this . setByInteger ( params [ 'int' ] ) ; } else if ( typeof params == "number" ) { this . setByInteger ( params ) ; } else if ( typeof params [ 'hex' ] != "undefined" ) { this . setValueHex ( params [ 'hex' ] ) ; } } } ; YAHOO . lang . extend ( KJUR . asn1 . DEREnumerated , KJUR . asn1 . ASN1Object ) ; name class param { Array } params extends KJUR . asn1 . DERAbstractString description see KJUR . asn1 . DERAbstractString KJUR . asn1 . DERUTF8String = function ( params ) { KJUR . asn1 . DERUTF8String . superclass . constructor . call ( this , params ) ; this . hT = "0c" ; } ; YAHOO . lang . extend ( KJUR . asn1 . DERUTF8String , KJUR . asn1 . DERAbstractString ) ; name class param { Array } params extends KJUR . asn1 . DERAbstractString description see KJUR . asn1 . DERAbstractString KJUR . asn1 . DERNumericString = function ( params ) { KJUR . asn1 . DERNumericString . superclass . constructor . call ( this , params ) ; this . hT = "12" ; } ; YAHOO . lang . extend ( KJUR . asn1 . DERNumericString , KJUR . asn1 . DERAbstractString ) ; name class param { Array } params extends KJUR . asn1 . DERAbstractString description see KJUR . asn1 . DERAbstractString KJUR . asn1 . DERPrintableString = function ( params ) { KJUR . asn1 . DERPrintableString . superclass . constructor . call ( this , params ) ; this . hT = "13" ; } ; YAHOO . lang . extend ( KJUR . asn1 . DERPrintableString , KJUR . asn1 . DERAbstractString ) ; name class param { Array } params extends KJUR . asn1 . DERAbstractString description see KJUR . asn1 . DERAbstractString KJUR . asn1 . DERTeletexString = function ( params ) { KJUR . asn1 . DERTeletexString . superclass . constructor . call ( this , params ) ; this . hT = "14" ; } ; YAHOO . lang . extend ( KJUR . asn1 . DERTeletexString , KJUR . asn1 . DERAbstractString ) ; name class param { Array } params extends KJUR . asn1 . DERAbstractString description see KJUR . asn1 . DERAbstractString KJUR . asn1 . DERIA5String = function ( params ) { KJUR . asn1 . DERIA5String . superclass . constructor . call ( this , params ) ; this . hT = "16" ; } ; YAHOO . lang . extend ( KJUR . asn1 . DERIA5String , KJUR . asn1 . DERAbstractString ) ; name class param { Array } params extends KJUR . asn1 . DERAbstractTime description example KJUR . asn1 . DERUTCTime = function ( params ) { KJUR . asn1 . DERUTCTime . superclass . constructor . call ( this , params ) ; this . hT = "17" ; name memberOf function param { Date } dateObject example this . setByDate = function ( dateObject ) { this . hTLV = null ; this . isModified = true ; this . date = dateObject ; this . s = this . formatDate ( this . date , 'utc' ) ; this . hV = stohex ( this . s ) ; } ; this . getFreshValueHex = function ( ) { if ( typeof this . date == "undefined" && typeof this . s == "undefined" ) { this . date = new Date ( ) ; this . s = this . formatDate ( this . date , 'utc' ) ; this . hV = stohex ( this . s ) ; } return this . hV ; } ; if ( params !== undefined ) { if ( params . str !== undefined ) { this . setString ( params . str ) ; } else if ( typeof params == "string" && params . match ( /^[0-9]{12}Z$/ ) ) { this . setString ( params ) ; } else if ( params . hex !== undefined ) { this . setStringHex ( params . hex ) ; } else if ( params . date !== undefined ) { this . setByDate ( params . date ) ; } } } ; YAHOO . lang . extend ( KJUR . asn1 . DERUTCTime , KJUR . asn1 . DERAbstractTime ) ; name class param { Array } params property extends KJUR . asn1 . DERAbstractTime description KJUR . asn1 . DERGeneralizedTime = function ( params ) { KJUR . asn1 . DERGeneralizedTime . superclass . constructor . call ( this , params ) ; this . hT = "18" ; this . withMillis = false ; name memberOf function param { Date } dateObject example this . setByDate = function ( dateObject ) { this . hTLV = null ; this . isModified = true ; this . date = dateObject ; this . s = this . formatDate ( this . date , 'gen' , this . withMillis ) ; this . hV = stohex ( this . s ) ; } ; this . getFreshValueHex = function ( ) { if ( this . date === undefined && this . s === undefined ) { this . date = new Date ( ) ; this . s = this . formatDate ( this . date , 'gen' , this . withMillis ) ; this . hV = stohex ( this . s ) ; } return this . hV ; } ; if ( params !== undefined ) { if ( params . str !== undefined ) { this . setString ( params . str ) ; } else if ( typeof params == "string" && params . match ( /^[0-9]{14}Z$/ ) ) { this . setString ( params ) ; } else if ( params . hex !== undefined ) { this . setStringHex ( params . hex ) ; } else if ( params . date !== undefined ) { this . setByDate ( params . date ) ; } if ( params . millis === true ) { this . withMillis = true ; } } } ; YAHOO . lang . extend ( KJUR . asn1 . DERGeneralizedTime , KJUR . asn1 . DERAbstractTime ) ; name class extends KJUR . asn1 . DERAbstractStructured description KJUR . asn1 . DERSequence = function ( params ) { KJUR . asn1 . DERSequence . superclass . constructor . call ( this , params ) ; this . hT = "30" ; this . getFreshValueHex = function ( ) { var h = '' ; for ( var i = 0 ; i < this . asn1Array . length ; i ++ ) { var asn1Obj = this . asn1Array [ i ] ; h += asn1Obj . getEncodedHex ( ) ; } this . hV = h ; return this . hV ; } ; } ; YAHOO . lang . extend ( KJUR . asn1 . DERSequence , KJUR . asn1 . DERAbstractStructured ) ; name class extends KJUR . asn1 . DERAbstractStructured description KJUR . asn1 . DERSet = function ( params ) { KJUR . asn1 . DERSet . superclass . constructor . call ( this , params ) ; this . hT = "31" ; this . sortFlag = true ; this . getFreshValueHex = function ( ) { var a = new Array ( ) ; for ( var i = 0 ; i < this . asn1Array . length ; i ++ ) { var asn1Obj = this . asn1Array [ i ] ; a . push ( asn1Obj . getEncodedHex ( ) ) ; } if ( this . sortFlag == true ) a . sort ( ) ; this . hV = a . join ( '' ) ; return this . hV ; } ; if ( typeof params != "undefined" ) { if ( typeof params . sortflag != "undefined" && params . sortflag == false ) this . sortFlag = false ; } } ; YAHOO . lang . extend ( KJUR . asn1 . DERSet , KJUR . asn1 . DERAbstractStructured ) ; name class extends KJUR . asn1 . ASN1Object description example KJUR . asn1 . DERTaggedObject = function ( params ) { KJUR . asn1 . DERTaggedObject . superclass . constructor . call ( this ) ; this . hT = "a0" ; this . hV = '' ; this . isExplicit = true ; this . asn1Object = null ; name memberOf function param { Boolean } isExplicitFlag param { Integer } tagNoHex param { ASN1Object } asn1Object this . setASN1Object = function ( isExplicitFlag , tagNoHex , asn1Object ) { this . hT = tagNoHex ; this . isExplicit = isExplicitFlag ; this . asn1Object = asn1Object ; if ( this . isExplicit ) { this . hV = this . asn1Object . getEncodedHex ( ) ; this . hTLV = null ; this . isModified = true ; } else { this . hV = null ; this . hTLV = asn1Object . getEncodedHex ( ) ; this . hTLV = this . hTLV . replace ( /^../ , tagNoHex ) ; this . isModified = false ; } } ; this . getFreshValueHex = function ( ) { return this . hV ; } ; if ( typeof params != "undefined" ) { if ( typeof params [ 'tag' ] != "undefined" ) { this . hT = params [ 'tag' ] ; } if ( typeof params [ 'explicit' ] != "undefined" ) { this . isExplicit = params [ 'explicit' ] ; } if ( typeof params [ 'obj' ] != "undefined" ) { this . asn1Object = params [ 'obj' ] ; this . setASN1Object ( this . isExplicit , this . hT , this . asn1Object ) ; } } } ; YAHOO . lang . extend ( KJUR . asn1 . DERTaggedObject , KJUR . asn1 . ASN1Object ) ;