-
-
Notifications
You must be signed in to change notification settings - Fork 647
/
qunit-do-asn1-newobj.html
executable file
·190 lines (147 loc) · 7.68 KB
/
qunit-do-asn1-newobj.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<title>QUnit for ASN1 Encoder Class 'asn1.js' ASN1Util.newObject</title>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />
<!-- getPEM -->
<script src="../ext/jsbn.js"></script>
<script src="../ext/jsbn2.js"></script>
<script src="../ext/base64.js"></script>
<script src="../src/base64x-1.1.js"></script>
<script src="../src/asn1hex-1.1.js"></script>
<script src="../src/asn1-1.0.js"></script>
<script src="../src/asn1x509-1.0.js"></script>
<script type="text/javascript">
<!--
$(document).ready(function(){
// ======= TEST ===============================================================
test("asn1 test", function() {
equal(KJUR.asn1.ASN1Util.newObject({'asn1': {'tlv': '030101'}}).getEncodedHex(), "030101", "asn1 tlv=030101");
});
test("boolean test", function() {
equal(KJUR.asn1.ASN1Util.newObject({'bool': {}}).getEncodedHex(), "0101ff", "boolean test1");
});
test("int test", function() {
var pIn;
var _newObject = KJUR.asn1.ASN1Util.newObject;
pIn = {"int": 3};
equal(_newObject(pIn).getEncodedHex(), "020103", "{int: 3}");
pIn = {"int": {"int": 3}};
equal(_newObject(pIn).getEncodedHex(), "020103", "{int: {int: 3}}");
pIn = {"int": {"bigint": new BigInteger("123456", 10)}};
equal(_newObject(pIn).getEncodedHex(), "020301e240", "{int: {bigint: new BigInteger(123456,10}}");
pIn = {"int": {"bigint": new BigInteger("1abcd", 16)}};
equal(_newObject(pIn).getEncodedHex(), "020301abcd", "{int: {bigint: new BigInteger(1abcd,16}}");
pIn = {"int": {"hex": "01abcd"}};
equal(_newObject(pIn).getEncodedHex(), "020301abcd", "{int: {hex: 1abcd}}");
});
test("bitstr test unused:0 1a2b", function() {
equal(KJUR.asn1.ASN1Util.newObject({'bitstr': {'hex': '001a2b'}}).getEncodedHex(), "0303001a2b", "test1");
});
test("bitstr test unused:0 1a2b", function() {
equal(KJUR.asn1.ASN1Util.newObject({'bitstr': '001a2b'}).getEncodedHex(), "0303001a2b", "test1");
});
test("octstr test", function() {
equal(KJUR.asn1.ASN1Util.newObject({'octstr': {'hex': '1a2b'}}).getEncodedHex(), "04021a2b", "test1 04021a2b");
equal(KJUR.asn1.ASN1Util.newObject({'octstr': 'abc'}).getEncodedHex(), "0403616263", "test1 abc=0403616263");
});
test("null test", function() {
equal(KJUR.asn1.ASN1Util.newObject({'null': {}}).getEncodedHex(), "0500", "test1");
});
test("oid test", function() {
equal(KJUR.asn1.ASN1Util.newObject({'oid': {'oid': '2.5.4.5'}}).getEncodedHex(), "0603550405", "{oid: {oid: 2.5.4.5}}");
equal(KJUR.asn1.ASN1Util.newObject({'oid': '2.5.4.5'}).getEncodedHex(), "0603550405", "{oid: 2.5.4.5}");
equal(KJUR.asn1.ASN1Util.newObject({'oid': 'keyUsage'}).getEncodedHex(), "0603551d0f", "keyUsage");
equal(KJUR.asn1.ASN1Util.newObject({'oid': 'countryName'}).getEncodedHex(), "0603550406", "countryName");
});
test("utf8str test", function() {
equal(KJUR.asn1.ASN1Util.newObject({'utf8str': {'str': 'aaa'}}).getEncodedHex(), "0c03616161", "test1");
equal(KJUR.asn1.ASN1Util.newObject({'utf8str': 'aaa'}).getEncodedHex(), "0c03616161", "test1");
});
test("numstr test", function() {
equal(KJUR.asn1.ASN1Util.newObject({'numstr': {'str': '123'}}).getEncodedHex(), "1203313233", "{str: 123}");
equal(KJUR.asn1.ASN1Util.newObject({'numstr': '123'}).getEncodedHex(), "1203313233", "123");
});
test("prnstr test aaa", function() {
equal(KJUR.asn1.ASN1Util.newObject({'prnstr': {'str': 'aaa'}}).getEncodedHex(), "1303616161", "{str: aaa}");
equal(KJUR.asn1.ASN1Util.newObject({'prnstr': 'aaa'}).getEncodedHex(), "1303616161", "aaa");
});
test("telstr test", function() {
equal(KJUR.asn1.ASN1Util.newObject({'telstr': {'str': 'aaa'}}).getEncodedHex(), "1403616161", "{str: aaa}");
equal(KJUR.asn1.ASN1Util.newObject({'telstr': 'aaa'}).getEncodedHex(), "1403616161", "aaa");
});
test("ia5str test", function() {
equal(KJUR.asn1.ASN1Util.newObject({'ia5str': {'str': 'aaa'}}).getEncodedHex(), "1603616161", "test1");
equal(KJUR.asn1.ASN1Util.newObject({'ia5str': 'aaa'}).getEncodedHex(), "1603616161", "test1");
});
test("utctime test", function() {
equal(KJUR.asn1.ASN1Util.newObject({'utctime': {'str': '491231235959Z'}}).getEncodedHex(), "170d3439313233313233353935395a", "test1");
equal(KJUR.asn1.ASN1Util.newObject({'utctime': '491231235959Z'}).getEncodedHex(), "170d3439313233313233353935395a", "test1");
});
test("gentime test", function() {
equal(KJUR.asn1.ASN1Util.newObject({'gentime': {'str': '20131231235959Z'}}).getEncodedHex(), "180f32303133313233313233353935395a", "test1");
equal(KJUR.asn1.ASN1Util.newObject({'gentime': '20131231235959Z'}).getEncodedHex(), "180f32303133313233313233353935395a", "test1");
});
test("visstr test", function() {
equal(KJUR.asn1.ASN1Util.newObject({'visstr': {'str': 'aaa'}}).getEncodedHex(), "1a03616161", "{str: aaa}");
equal(KJUR.asn1.ASN1Util.newObject({'visstr': 'aaa'}).getEncodedHex(), "1a03616161", "aaa");
});
test("bmpstr test", function() {
equal(KJUR.asn1.ASN1Util.newObject({'bmpstr': {'str': 'aaa'}}).getEncodedHex(), "1e03616161", "{str: aaa}");
equal(KJUR.asn1.ASN1Util.newObject({'bmpstr': 'aaa'}).getEncodedHex(), "1e03616161", "aaa");
});
test("seq test", function() {
equal(KJUR.asn1.ASN1Util.newObject({'seq': [{'int': 3}]}).getEncodedHex(), "3003020103", "[int 3]");
equal(KJUR.asn1.ASN1Util.newObject({'seq': [{'int': 3}, {'int': 4}]}).getEncodedHex(), "3006020103020104", "[int 3, int 4]");
});
test("set test", function() {
equal(KJUR.asn1.ASN1Util.newObject({'set': [{'int': 3}]}).getEncodedHex(), "3103020103", "[int 3]");
equal(KJUR.asn1.ASN1Util.newObject({'set': [{'int': 3}, {'int': 4}]}).getEncodedHex(), "3106020103020104", "[int 3, int 4]");
});
test("tag test seq [int 3, int 4] implicit", function() {
equal(KJUR.asn1.ASN1Util.newObject({'tag': {'tag': 'a1', 'explicit': false, 'obj': {'seq': [{'int': 3}, {'int': 4}]}}}).getEncodedHex(), "a106020103020104", "test1");
});
test("tag test seq [int 3, int 4] explicit", function() {
equal(KJUR.asn1.ASN1Util.newObject({'tag': {'tag': 'a1', 'explicit': true, 'obj': {'seq': [{'int': 3}, {'int': 4}]}}}).getEncodedHex(), "a1083006020103020104", "test1");
});
test("tag test seq [int 3, int 4] explicit", function() {
equal(KJUR.asn1.ASN1Util.newObject({'tag': ['a1', true, {'seq': [{'int': 3}, {'int': 4}]}]}).getEncodedHex(), "a1083006020103020104", "test1");
});
test("tag test", function() {
var pIn;
var _newObject = KJUR.asn1.ASN1Util.newObject;
pIn = {tag: {tagi: "81", hex: "04"}};
equal(_newObject(pIn).getEncodedHex(), "810104", "{tagi:81,hex:04}");
pIn = {tag: {tagi: "80", obj: {"int": {"int": 3}}}};
equal(_newObject(pIn).getEncodedHex(), "800103", "80 int:3");
pIn = {tag: {tage: "a3", obj: {seq: [{'int': 3}, {'int': 4}]}}};
equal(_newObject(pIn).getEncodedHex(), "a3083006020103020104", "a3 seq");
pIn = {tag: {tagi: "a4", obj: {seq: [{'int': 3}, {'int': 4}]}}};
equal(_newObject(pIn).getEncodedHex(), "a406020103020104", "a4 seq");
});
test("tag test RFC 3161 TSP Accuracy 500ms", function() {
equal(KJUR.asn1.ASN1Util.newObject(
{seq: [{tag: {tag: '80', explicit: false, obj: {int: 500}}}]}).getEncodedHex(),
"3004800201f4", "test1");
});
test("jsonToASN1HEX test1", function() {
var result = KJUR.asn1.ASN1Util.jsonToASN1HEX({seq: [{int: 4}, {int: 5}]});
equal(result, "3006020104020105", "seq int int");
});
});
-->
</script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
<a href="index.html">TEST INDEX</a> |
<a href="../api/index.html">API</a> |
<a href="qunit-do-asn1.html">asn1</a> |
<a href="qunit-do-asn1-newobj.html">asn1-newobj</a> |
</body>
</html>