Created
February 7, 2020 13:21
-
-
Save OleksandrKucherenko/0ac3742dbe12b3d46be54defedb24e2d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.oblador.keychain; | |
import java.security.Provider; | |
import java.util.HashMap; | |
public final class FakeProvider extends Provider { | |
public static final String NAME = "AndroidKeyStore"; | |
public final HashMap<String, HashMap<String, MocksForProvider>> mocks = new HashMap<>(); | |
public final HashMap<String, Object> configuration = new HashMap<>(); | |
public FakeProvider() { | |
super(NAME, 1.0, "Fake"); | |
put("KeyStore.AndroidKeyStore", FakeKeyStoreSpi.class.getName()); | |
} | |
@Override | |
public synchronized Service getService(String type, String algorithm) { | |
MocksForProvider mock; | |
HashMap<String, MocksForProvider> inner; | |
if (null == (inner = mocks.get(type))) { | |
mocks.put(type, (inner = new HashMap<>())); | |
} | |
if (null == (mock = inner.get(algorithm))) { | |
inner.put(algorithm, (mock = new MocksForProvider())); | |
} | |
mock.configure(type, this, configuration); | |
return mock.service; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment