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: package org.apache.harmony.security.tests.x509.tsp;
19:
20: import java.io.IOException;
21: import java.math.BigInteger;
22: import java.util.Arrays;
23: import java.util.Date;
24:
25: import junit.framework.TestCase;
26:
27: import org.apache.harmony.security.x501.Name;
28: import org.apache.harmony.security.x509.AlgorithmIdentifier;
29: import org.apache.harmony.security.x509.Extension;
30: import org.apache.harmony.security.x509.Extensions;
31: import org.apache.harmony.security.x509.GeneralName;
32: import org.apache.harmony.security.x509.tsp.MessageImprint;
33: import org.apache.harmony.security.x509.tsp.TSTInfo;
34:
35: public class TSTInfoTest extends TestCase {
36:
37: /**
38: * @throws IOException
39: * @tests 'org.apache.harmony.security.x509.tsp.TSTInfo.getEncoded()'
40: */
41: public void testGetEncoded() throws IOException {
42: // Unizeto CETRUM policy
43: String policy = "1.2.3.4.5";
44: // SHA1 OID as defined in RFC 3161
45: String sha1 = "1.3.14.3.2.26";
46: MessageImprint msgImprint = new MessageImprint(
47: new AlgorithmIdentifier(sha1), new byte[20]);
48: Date genTime = new Date();
49: BigInteger nonce = BigInteger.valueOf(1234567890L);
50: int[] accuracy = new int[] { 1, 0, 0 };
51: GeneralName tsa = new GeneralName(new Name("CN=AnAuthority"));
52: Extensions exts = new Extensions();
53: // Time-Stamping extension OID: as defined in RFC 3161
54: int[] timeStampingExtOID = new int[] { 1, 3, 6, 1, 5, 5, 7, 3,
55: 8 };
56: byte[] timeStampingExtValue = new byte[] { (byte) 1, (byte) 2,
57: (byte) 3 };
58: Extension ext = new Extension(timeStampingExtOID, true,
59: timeStampingExtValue);
60: exts.addExtension(ext);
61:
62: TSTInfo info = new TSTInfo(1, policy, msgImprint,
63: BigInteger.TEN, genTime, accuracy, Boolean.FALSE,
64: nonce, tsa, exts);
65:
66: byte[] encoding = TSTInfo.ASN1.encode(info);
67: TSTInfo decoded = (TSTInfo) TSTInfo.ASN1.decode(encoding);
68:
69: assertEquals("Decoded version is incorrect", info.getVersion(),
70: decoded.getVersion());
71: assertEquals("Decoded policy is incorrect", policy, decoded
72: .getPolicy());
73: assertTrue("Decoded messageImprint is incorrect", Arrays
74: .equals(MessageImprint.ASN1.encode(msgImprint),
75: MessageImprint.ASN1.encode(decoded
76: .getMessageImprint())));
77: assertEquals("Decoded serialNumber is incorrect",
78: BigInteger.TEN, decoded.getSerialNumber());
79: assertEquals("Decoded genTime is incorrect", genTime, decoded
80: .getGenTime());
81: assertTrue("Decoded accuracy is incorrect", Arrays.equals(
82: accuracy, decoded.getAccuracy()));
83: assertFalse("Decoded ordering is incorrect", decoded
84: .getOrdering().booleanValue());
85: assertEquals("Decoded nonce is incorrect", nonce, decoded
86: .getNonce());
87: assertEquals("Decoded tsa is incorrect", tsa, decoded.getTsa());
88: assertEquals("Decoded extensions is incorrect", exts, decoded
89: .getExtensions());
90: }
91: }
|