1package org.bouncycastle.cms;
2
3import java.util.HashSet;
4import java.util.Set;
5
6import org.bouncycastle.asn1.DERNull;
7import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
8import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
9import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers;
10import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
11
12public class DefaultCMSSignatureEncryptionAlgorithmFinder
13    implements CMSSignatureEncryptionAlgorithmFinder
14{
15    private static final Set RSA_PKCS1d5 = new HashSet();
16
17    static
18    {
19        // BEGIN android-removed
20        // RSA_PKCS1d5.add(PKCSObjectIdentifiers.md2WithRSAEncryption);
21        // RSA_PKCS1d5.add(PKCSObjectIdentifiers.md4WithRSAEncryption);
22        // END android-removed
23        RSA_PKCS1d5.add(PKCSObjectIdentifiers.md5WithRSAEncryption);
24        RSA_PKCS1d5.add(PKCSObjectIdentifiers.sha1WithRSAEncryption);
25        RSA_PKCS1d5.add(PKCSObjectIdentifiers.sha224WithRSAEncryption);
26        RSA_PKCS1d5.add(PKCSObjectIdentifiers.sha256WithRSAEncryption);
27        RSA_PKCS1d5.add(PKCSObjectIdentifiers.sha384WithRSAEncryption);
28        RSA_PKCS1d5.add(PKCSObjectIdentifiers.sha512WithRSAEncryption);
29        // BEGIN android-removed
30        // RSA_PKCS1d5.add(OIWObjectIdentifiers.md4WithRSAEncryption);
31        // RSA_PKCS1d5.add(OIWObjectIdentifiers.md4WithRSA);
32        // END android-removed
33        RSA_PKCS1d5.add(OIWObjectIdentifiers.md5WithRSA);
34        RSA_PKCS1d5.add(OIWObjectIdentifiers.sha1WithRSA);
35        // BEGIN android-removed
36        // RSA_PKCS1d5.add(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128);
37        // RSA_PKCS1d5.add(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160);
38        // RSA_PKCS1d5.add(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256);
39        // END android-removed
40    }
41
42    public AlgorithmIdentifier findEncryptionAlgorithm(AlgorithmIdentifier signatureAlgorithm)
43    {
44               // RFC3370 section 3.2
45        if (RSA_PKCS1d5.contains(signatureAlgorithm.getAlgorithm()))
46        {
47            return new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE);
48        }
49
50        return signatureAlgorithm;
51    }
52}
53