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:
24: import junit.framework.TestCase;
25:
26: import org.apache.harmony.security.x509.AlgorithmIdentifier;
27: import org.apache.harmony.security.x509.Extension;
28: import org.apache.harmony.security.x509.Extensions;
29: import org.apache.harmony.security.x509.tsp.MessageImprint;
30: import org.apache.harmony.security.x509.tsp.TimeStampReq;
31:
32: public class TimeStampReqTest extends TestCase {
33:
34: /**
35: * @throws IOException
36: * @tests 'org.apache.harmony.security.x509.tsp.TimeStampReq.getEncoded()'
37: */
38: public void testTimeStampReq() throws IOException {
39: // SHA1 OID
40: MessageImprint msgImprint = new MessageImprint(
41: new AlgorithmIdentifier("1.3.14.3.2.26"), new byte[20]);
42: String reqPolicy = "1.2.3.4.5";
43: BigInteger nonce = BigInteger.valueOf(1234567890L);
44: Extensions exts = new Extensions();
45: int[] extOID = new int[] { 1, 2, 3, 2, 1 };
46: byte[] extValue = new byte[] { (byte) 1, (byte) 2, (byte) 3 };
47: Extension ext = new Extension(extOID, false, extValue);
48: exts.addExtension(ext);
49:
50: TimeStampReq req = new TimeStampReq(1, msgImprint, reqPolicy,
51: nonce, Boolean.FALSE, exts);
52: byte[] encoding = req.getEncoded();
53: TimeStampReq decoded = (TimeStampReq) TimeStampReq.ASN1
54: .decode(encoding);
55: assertEquals("Decoded version is incorrect", req.getVersion(),
56: decoded.getVersion());
57: assertTrue("Decoded messageImprint is incorrect", Arrays
58: .equals(MessageImprint.ASN1.encode(msgImprint),
59: MessageImprint.ASN1.encode(decoded
60: .getMessageImprint())));
61: assertEquals("Decoded reqPolicy is incorrect", reqPolicy,
62: decoded.getReqPolicy());
63: assertEquals("Decoded nonce is incorrect", nonce, decoded
64: .getNonce());
65: assertFalse("Decoded certReq is incorrect", decoded
66: .getCertReq().booleanValue());
67: assertEquals("Decoded extensions is incorrect", exts, decoded
68: .getExtensions());
69: }
70: }
|