01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Stepan M. Mishura
19: * @version $Revision$
20: */package org.apache.harmony.security.tests.x501;
21:
22: import java.io.ByteArrayInputStream;
23:
24: import org.apache.harmony.security.x501.Name;
25:
26: import junit.framework.TestCase;
27:
28: /**
29: * Test Name class
30: *
31: * @see http://www.ietf.org/rfc/rfc1779.txt
32: * @see http://www.ietf.org/rfc/rfc2253.txt
33: */
34: public class NameTest extends TestCase {
35:
36: private static final byte[] mess = {
37: 0x30, //0 seq of
38: (byte) 0x81,
39: (byte) 0x9A, //1 len = 154
40: 0x31,
41: 0x0A, //3,4
42: 0x30,
43: 0x08,
44: 0x06,
45: 0x03,
46: 0x55,
47: 0x04,
48: 0x03,
49: 0x13,
50: 0x01,
51: 0x5A,
52: 0x31,
53: 0x0A, //15,16
54: 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01, 0x45,
55: 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
56: 0x01, 0x44, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04,
57: 0x07, 0x13, 0x01, 0x43, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03,
58: 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30, 0x08,
59: 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30, 0x09,
60: 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41, 0x31,
61: 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x13, 0x01,
62: 0x45, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55, 0x04, 0x06,
63: 0x13, 0x01, 0x44, 0x31, 0x0A, 0x30, 0x08, 0x06, 0x03, 0x55,
64: 0x04, 0x07, 0x13, 0x01, 0x43, 0x31, 0x0A, 0x30, 0x08, 0x06,
65: 0x03, 0x55, 0x04, 0x0A, 0x13, 0x01, 0x42, 0x31, 0x15, 0x30,
66: 0x08, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x01, 0x41, 0x30,
67: 0x09, 0x06, 0x03, 0x55, 0x04, 0x08, 0x13, 0x02, 0x43, 0x41 };
68:
69: public static void main(String[] args) {
70: junit.textui.TestRunner.run(NameTest.class);
71: }
72:
73: public void testGetName1779() throws Exception {
74:
75: Name principal = (Name) Name.ASN1.decode(mess);
76:
77: String s = principal.getName("RFC1779");
78:
79: assertEquals(
80: "CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=Z",
81: s);
82: }
83:
84: public void testStreamGetName1779() throws Exception {
85: ByteArrayInputStream is = new ByteArrayInputStream(mess);
86:
87: Name principal = (Name) Name.ASN1.decode(is);
88:
89: String s = principal.getName("RFC1779");
90:
91: assertEquals(
92: "CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=A + ST=CA, O=B, L=C, C=D, OU=E, CN=Z",
93: s);
94: }
95: }
|