Skip to content

Commit

Permalink
ASN1HEX.dump ASN1Object support
Browse files Browse the repository at this point in the history
  • Loading branch information
kjur committed Dec 4, 2016
1 parent efe41f8 commit c9da618
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 24 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
ChangeLog for jsrsasign

* Changes from 6.2.3 to next version
- asn1hex 1.1.7 to 1.1.8
- ASN1HEX.dump also supports ASN1Object as argument
- asn1x509
- API document update

Expand Down
38 changes: 26 additions & 12 deletions asn1hex-1.1.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! asn1hex-1.1.7.js (c) 2012-2016 Kenji Urushima | kjur.github.com/jsrsasign/license
/*! asn1hex-1.1.8.js (c) 2012-2016 Kenji Urushima | kjur.github.com/jsrsasign/license
*/
/*
* asn1hex.js - Hexadecimal represented ASN.1 string library
Expand All @@ -16,7 +16,7 @@
* @fileOverview
* @name asn1hex-1.1.js
* @author Kenji Urushima [email protected]
* @version asn1hex 1.1.7 (2016-Oct-02)
* @version asn1hex 1.1.8 (2016-Dec-03)
* @license <a href="http://kjur.github.io/jsrsasign/license/">MIT License</a>
*/

Expand Down Expand Up @@ -405,14 +405,14 @@ ASN1HEX.hextooidstr = function(hex) {
};

/**
* get string of simple ASN.1 dump from hexadecimal ASN.1 data
* get string of simple ASN.1 dump from hexadecimal ASN.1 data<br/>
* @name dump
* @memberOf ASN1HEX
* @function
* @param {String} hex hexadecmal string of ASN.1 data
* @param {Array} associative array of flags for dump (OPTION)
* @param {Object} hexOrObj hexadecmal string of ASN.1 data or ASN1Object object
* @param {Array} flags associative array of flags for dump (OPTION)
* @param {Number} idx string index for starting dump (OPTION)
* @param {String} indent string (OPTION)
* @param {String} indent indent string (OPTION)
* @return {String} string of simple ASN.1 dump
* @since jsrsasign 4.8.3 asn1hex 1.1.6
* @description
Expand All @@ -433,25 +433,34 @@ ASN1HEX.hextooidstr = function(hex) {
* </ul>
* </li>
* </ul>
* NOTE1: Argument {@link KJUR.asn1.ASN1Object} object is supported since
* jsrsasign 6.2.4 asn1hex 1.0.8
* @example
* // ASN.1 INTEGER
* // 1) ASN.1 INTEGER
* ASN1HEX.dump('0203012345')
* &darr;
* INTEGER 012345
*
* // ASN.1 Object Identifier
* // 2) ASN.1 Object Identifier
* ASN1HEX.dump('06052b0e03021a')
* &darr;
* ObjectIdentifier sha1 (1 3 14 3 2 26)
*
* // ASN.1 SEQUENCE
* // 3) ASN.1 SEQUENCE
* ASN1HEX.dump('3006020101020102')
* &darr;
* SEQUENCE
* INTEGER 01
* INTEGER 02
*
* // ASN.1 DUMP FOR X.509 CERTIFICATE
* // 4) ASN.1 SEQUENCE since jsrsasign 6.2.4
* o = KJUR.asn1.ASN1Util.newObject({seq: [{int: 1}, {int: 2}]});
* ASN1HEX.dump(o)
* &darr;
* SEQUENCE
* INTEGER 01
* INTEGER 02
* // 5) ASN.1 DUMP FOR X.509 CERTIFICATE
* ASN1HEX.dump(X509.pemToHex(certPEM))
* &darr;
* SEQUENCE
Expand All @@ -469,7 +478,11 @@ ASN1HEX.hextooidstr = function(hex) {
* PrintableString 'US'
* :
*/
ASN1HEX.dump = function(hex, flags, idx, indent) {
ASN1HEX.dump = function(hexOrObj, flags, idx, indent) {
var hex = hexOrObj;
if (hexOrObj instanceof KJUR.asn1.ASN1Object)
hex = hexOrObj.getEncodedHex();

var _skipLongHex = function(hex, limitNumOctet) {
if (hex.length <= limitNumOctet * 2) {
return hex;
Expand Down Expand Up @@ -603,7 +616,8 @@ ASN1HEX.dump = function(hex, flags, idx, indent) {
return s;
}
}
return indent + "UNKNOWN(" + hex.substr(idx, 2) + ") " + ASN1HEX.getHexOfV_AtObj(hex, idx) + "\n";
return indent + "UNKNOWN(" + hex.substr(idx, 2) + ") " +
ASN1HEX.getHexOfV_AtObj(hex, idx) + "\n";
};

/**
Expand Down
7 changes: 7 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ <h2 id="project_tagline">opensource free pure JavaScript cryptographic library s
<section id="main_content" class="inner">

<!-- now editing -->
<br clear="all"/>
<img src="https://img.shields.io/badge/license-MIT-green.svg" alt=""/>
<img src="https://img.shields.io/bower/v/jsrsasign.svg?maxAge=2592000" alt=""/>
<img src="https://badge.fury.io/js/jsrsasign.svg?maxAge=2592000" alt=""/>
<img src="https://img.shields.io/cdnjs/v/jsrsasign.svg?maxAge=2592000" alt=""/>
<br clear="all"/>

<h3>FEATURES</h3>
The 'jsrsasign' library provides following features in pure JavaScript.
<ul>
Expand Down
28 changes: 16 additions & 12 deletions test/qunit-do-asn1hex-dump.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@
PrintableString 'US'
SET
SEQUENCE
ObjectIdentifier organization (2 5 4 10)
ObjectIdentifier organizationName (2 5 4 10)
PrintableString 'DigiCert Inc'
SET
SEQUENCE
ObjectIdentifier organizationalUnit (2 5 4 11)
ObjectIdentifier organizationalUnitName (2 5 4 11)
PrintableString 'www.digicert.com'
SET
SEQUENCE
Expand All @@ -90,27 +90,27 @@
SEQUENCE
SET
SEQUENCE
ObjectIdentifier (2 5 4 15)
ObjectIdentifier businessCategory (2 5 4 15)
UTF8String 'Private Organization'
SET
SEQUENCE
ObjectIdentifier (1 3 6 1 4 1 311 60 2 1 3)
ObjectIdentifier jurisdictionOfIncorporationC (1 3 6 1 4 1 311 60 2 1 3)
PrintableString 'US'
SET
SEQUENCE
ObjectIdentifier (1 3 6 1 4 1 311 60 2 1 2)
ObjectIdentifier jurisdictionOfIncorporationSP (1 3 6 1 4 1 311 60 2 1 2)
PrintableString 'Delaware'
SET
SEQUENCE
ObjectIdentifier (2 5 4 5)
PrintableString '5157550'
SET
SEQUENCE
ObjectIdentifier (2 5 4 9)
ObjectIdentifier streetAddress (2 5 4 9)
PrintableString '548 4th Street'
SET
SEQUENCE
ObjectIdentifier (2 5 4 17)
ObjectIdentifier postalCode (2 5 4 17)
PrintableString '94107'
SET
SEQUENCE
Expand All @@ -122,11 +122,11 @@
PrintableString 'California'
SET
SEQUENCE
ObjectIdentifier locality (2 5 4 7)
ObjectIdentifier localityName (2 5 4 7)
PrintableString 'San Francisco'
SET
SEQUENCE
ObjectIdentifier organization (2 5 4 10)
ObjectIdentifier organizationName (2 5 4 10)
PrintableString 'GitHub, Inc.'
SET
SEQUENCE
Expand Down Expand Up @@ -192,10 +192,10 @@
OCTETSTRING, encapsulates
SEQUENCE
SEQUENCE
ObjectIdentifier (1 3 6 1 5 5 7 48 1)
ObjectIdentifier ocsp (1 3 6 1 5 5 7 48 1)
[6] http://ocsp.digicert.com
SEQUENCE
ObjectIdentifier (1 3 6 1 5 5 7 48 2)
ObjectIdentifier caIssuers (1 3 6 1 5 5 7 48 2)
[6] http://cacerts.digicert.com/DigiCertSHA2ExtendedValidationServerCA.crt
SEQUENCE
ObjectIdentifier basicConstraints (2 5 29 19)
Expand Down Expand Up @@ -253,6 +253,11 @@
"long int");
});

test("ASN1HEX.dump ASN1Object", function() {
equal(ASN1HEX.dump(KJUR.asn1.ASN1Util.newObject({seq: [{int: 1}, {int: 2}]})),
"SEQUENCE\n INTEGER 01\n INTEGER 02\n", "ASN1Object SEQ INT 1 INT 2");
});

test("ASN1HEX.isASN1HEX", function() {
equal(ASN1HEX.isASN1HEX('3006020101020102'), true, "3006020101020102");
equal(ASN1HEX.isASN1HEX('300602010102010202'), false, "300602010102010202 extra 02");
Expand All @@ -264,7 +269,6 @@
equal(ASN1HEX.dump(hCert), certGithubDump, "certGithubPEM");
});


});

</script>
Expand Down
1 change: 1 addition & 0 deletions test/qunit-do-x509.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<script src="../x509-1.1.js"></script>
<script src="../asn1-1.0.js"></script>
<script src="../asn1x509-1.0.js"></script>
<script src="../base64x-1.1.js"></script>

<script type="text/javascript">
$(document).ready(function(){
Expand Down

0 comments on commit c9da618

Please sign in to comment.