TimeStampReqTest.java revision 561ee011997c6c2f1befbfaa9d5f0a99771c1d63
1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * 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 18package org.apache.harmony.security.tests.x509.tsp; 19 20import java.io.IOException; 21import java.math.BigInteger; 22import java.util.Arrays; 23 24import junit.framework.TestCase; 25 26import org.apache.harmony.security.x509.AlgorithmIdentifier; 27import org.apache.harmony.security.x509.Extension; 28import org.apache.harmony.security.x509.Extensions; 29import org.apache.harmony.security.x509.tsp.MessageImprint; 30import org.apache.harmony.security.x509.tsp.TimeStampReq; 31 32public 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(new AlgorithmIdentifier( 41 "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(), decoded 56 .getVersion()); 57 assertTrue("Decoded messageImprint is incorrect", Arrays.equals( 58 MessageImprint.ASN1.encode(msgImprint), MessageImprint.ASN1 59 .encode(decoded.getMessageImprint()))); 60 assertEquals("Decoded reqPolicy is incorrect", reqPolicy, decoded 61 .getReqPolicy()); 62 assertEquals("Decoded nonce is incorrect", nonce, decoded.getNonce()); 63 assertFalse("Decoded certReq is incorrect", decoded.getCertReq() 64 .booleanValue()); 65 assertEquals("Decoded extensions is incorrect", exts, decoded 66 .getExtensions()); 67 } 68} 69 70