1package libcore.java.security.cert;
2
3import java.security.InvalidKeyException;
4import java.security.InvalidParameterException;
5import java.security.PrivateKey;
6import java.security.Provider;
7import java.security.PublicKey;
8import java.security.SignatureException;
9import java.security.SignatureSpi;
10
11public class FakeOidProvider extends Provider {
12    /**
13     * Used for testing some effects of algorithm OID mapping. We have to be
14     * slightly careful of the OID we pick here: the first number has to be 0,
15     * 1, or 2, and the second number has to be less than 39.
16     */
17    public static final String SIGALG_OID = "1.2.34359737229.1.1.5";
18
19    /**
20     * Used for testing some effects of algorithm OID mapping.
21     */
22    public static final String SIGALG_OID_NAME = "FAKEwithFAKE";
23
24    public static final String PROVIDER_NAME = "FakeOidProvider";
25
26    protected FakeOidProvider() {
27        super(PROVIDER_NAME, 1.0, "Fake OID Provider for Tests");
28
29        put("Signature." + SIGALG_OID, FakeOidSignature.class.getName());
30    }
31
32    public static class FakeOidSignature extends SignatureSpi {
33        @Override
34        protected void engineInitVerify(PublicKey publicKey) throws InvalidKeyException {
35        }
36
37        @Override
38        protected void engineInitSign(PrivateKey privateKey) throws InvalidKeyException {
39        }
40
41        @Override
42        protected void engineUpdate(byte b) throws SignatureException {
43        }
44
45        @Override
46        protected void engineUpdate(byte[] b, int off, int len) throws SignatureException {
47        }
48
49        @Override
50        protected byte[] engineSign() throws SignatureException {
51            return null;
52        }
53
54        @Override
55        protected boolean engineVerify(byte[] sigBytes) throws SignatureException {
56            return true;
57        }
58
59        @Override
60        protected void engineSetParameter(String param, Object value)
61                throws InvalidParameterException {
62        }
63
64        @Override
65        protected Object engineGetParameter(String param) throws InvalidParameterException {
66            return null;
67        }
68    }
69}
70