home *** CD-ROM | disk | FTP | other *** search
- package java.security;
-
- import java.security.cert.Certificate;
- import java.security.cert.X509Certificate;
- import java.security.spec.AlgorithmParameterSpec;
- import java.util.Set;
-
- public abstract class Signature extends SignatureSpi {
- private static final boolean debug = false;
- private String algorithm;
- private Provider provider;
- protected static final int UNINITIALIZED = 0;
- protected static final int SIGN = 2;
- protected static final int VERIFY = 3;
- protected int state = 0;
-
- protected Signature(String var1) {
- this.algorithm = var1;
- }
-
- public static Signature getInstance(String var0) throws NoSuchAlgorithmException {
- try {
- Object[] var1 = Security.getImpl(var0, "Signature", (String)null);
- if (var1[0] instanceof Signature) {
- Signature var4 = (Signature)var1[0];
- var4.provider = (Provider)var1[1];
- return var4;
- } else {
- Delegate var2 = new Delegate((SignatureSpi)var1[0], var0);
- var2.provider = (Provider)var1[1];
- return var2;
- }
- } catch (NoSuchProviderException var3) {
- throw new NoSuchAlgorithmException(var0 + " not found");
- }
- }
-
- public static Signature getInstance(String var0, String var1) throws NoSuchAlgorithmException, NoSuchProviderException {
- if (var1 != null && var1.length() != 0) {
- Object[] var2 = Security.getImpl(var0, "Signature", var1);
- if (var2[0] instanceof Signature) {
- Signature var4 = (Signature)var2[0];
- var4.provider = (Provider)var2[1];
- return var4;
- } else {
- Delegate var3 = new Delegate((SignatureSpi)var2[0], var0);
- var3.provider = (Provider)var2[1];
- return var3;
- }
- } else {
- throw new IllegalArgumentException("missing provider");
- }
- }
-
- public final Provider getProvider() {
- return this.provider;
- }
-
- public final void initVerify(PublicKey var1) throws InvalidKeyException {
- ((SignatureSpi)this).engineInitVerify(var1);
- this.state = 3;
- }
-
- public final void initVerify(Certificate var1) throws InvalidKeyException {
- if (var1 instanceof X509Certificate) {
- X509Certificate var2 = (X509Certificate)var1;
- Set var3 = var2.getCriticalExtensionOIDs();
- if (var3 != null && !var3.isEmpty() && var3.contains(new String("2.5.29.15"))) {
- boolean[] var4 = var2.getKeyUsage();
- if (var4 != null && !var4[0]) {
- throw new InvalidKeyException("Wrong key usage");
- }
- }
- }
-
- PublicKey var5 = var1.getPublicKey();
- ((SignatureSpi)this).engineInitVerify(var5);
- this.state = 3;
- }
-
- public final void initSign(PrivateKey var1) throws InvalidKeyException {
- ((SignatureSpi)this).engineInitSign(var1);
- this.state = 2;
- }
-
- public final void initSign(PrivateKey var1, SecureRandom var2) throws InvalidKeyException {
- ((SignatureSpi)this).engineInitSign(var1, var2);
- this.state = 2;
- }
-
- public final byte[] sign() throws SignatureException {
- if (this.state == 2) {
- return ((SignatureSpi)this).engineSign();
- } else {
- throw new SignatureException("object not initialized for signing");
- }
- }
-
- public final int sign(byte[] var1, int var2, int var3) throws SignatureException {
- if (var1 == null) {
- throw new IllegalArgumentException("No output buffer given");
- } else if (var1.length - var2 < var3) {
- throw new IllegalArgumentException("Output buffer too small for specified offset and length");
- } else if (this.state != 2) {
- throw new SignatureException("object not initialized for signing");
- } else {
- return ((SignatureSpi)this).engineSign(var1, var2, var3);
- }
- }
-
- public final boolean verify(byte[] var1) throws SignatureException {
- if (this.state == 3) {
- return ((SignatureSpi)this).engineVerify(var1);
- } else {
- throw new SignatureException("object not initialized for verification");
- }
- }
-
- public final void update(byte var1) throws SignatureException {
- if (this.state != 3 && this.state != 2) {
- throw new SignatureException("object not initialized for signature or verification");
- } else {
- ((SignatureSpi)this).engineUpdate(var1);
- }
- }
-
- public final void update(byte[] var1) throws SignatureException {
- this.update(var1, 0, var1.length);
- }
-
- public final void update(byte[] var1, int var2, int var3) throws SignatureException {
- if (this.state != 2 && this.state != 3) {
- throw new SignatureException("object not initialized for signature or verification");
- } else {
- ((SignatureSpi)this).engineUpdate(var1, var2, var3);
- }
- }
-
- public final String getAlgorithm() {
- return this.algorithm;
- }
-
- public String toString() {
- String var1 = "";
- switch (this.state) {
- case 0:
- var1 = "<not initialized>";
- case 1:
- default:
- break;
- case 2:
- var1 = "<initialized for signing>";
- break;
- case 3:
- var1 = "<initialized for verifying>";
- }
-
- return "Signature object: " + this.getAlgorithm() + var1;
- }
-
- public final void setParameter(String var1, Object var2) throws InvalidParameterException {
- ((SignatureSpi)this).engineSetParameter(var1, var2);
- }
-
- public final void setParameter(AlgorithmParameterSpec var1) throws InvalidAlgorithmParameterException {
- ((SignatureSpi)this).engineSetParameter(var1);
- }
-
- public final Object getParameter(String var1) throws InvalidParameterException {
- return ((SignatureSpi)this).engineGetParameter(var1);
- }
-
- public Object clone() throws CloneNotSupportedException {
- if (this instanceof Cloneable) {
- return super.clone();
- } else {
- throw new CloneNotSupportedException();
- }
- }
-
- private static void debug(String var0) {
- }
-
- private static void debug(Exception var0) {
- }
-
- // $FF: synthetic method
- static String access$000(Signature var0) {
- return var0.algorithm;
- }
-
- // $FF: synthetic method
- static Provider access$102(Signature var0, Provider var1) {
- return var0.provider = var1;
- }
-
- // $FF: synthetic method
- static Provider access$100(Signature var0) {
- return var0.provider;
- }
- }
-