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.pkcs7; 19 20import java.io.IOException; 21import java.io.InputStream; 22import java.util.List; 23 24import junit.framework.TestCase; 25 26import org.apache.harmony.security.pkcs7.ContentInfo; 27import org.apache.harmony.security.pkcs7.SignedData; 28import org.apache.harmony.security.pkcs7.SignerInfo; 29 30import tests.support.resource.Support_Resources; 31 32public class AuthenticatedAttributesTest extends TestCase { 33 34 private static final String tSTokenPath = "AuthenticatedAttributesTest.dat"; 35 36 public void testDecode() throws IOException { 37 InputStream in = Support_Resources.getResourceStream(tSTokenPath); 38 39 try { 40 // AuthenticatedAttributes is not public and can be created 41 // only as a part of ContentInfo. 42 ContentInfo token = (ContentInfo) ContentInfo.ASN1.decode(in); 43 SignedData sigData = token.getSignedData(); 44 SignerInfo sigInfo = (SignerInfo) sigData.getSignerInfos().get(0); 45 List authAttributes = sigInfo.getAuthenticatedAttributes(); 46 assertNotNull("Decoded AuthenticatedAttributes is null", 47 authAttributes); 48 assertEquals("Decoded AuthenticatedAttributes size is incorrect", 49 3, authAttributes.size()); 50 51 } finally { 52 in.close(); 53 } 54 } 55} 56