X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fbouncycastle%2Fasn1%2Fx509%2FAlgorithmIdentifier.java;fp=src%2Forg%2Fbouncycastle%2Fasn1%2Fx509%2FAlgorithmIdentifier.java;h=cad4c824bc9ef8028e3a8a2107b30fb4c903e0bc;hb=e5e9355b4f4e0e2c8de9068a71c1e3cc26fa9905;hp=0000000000000000000000000000000000000000;hpb=f35445729371789b3d496f426d7f87542f8e1a45;p=org.ibex.core.git diff --git a/src/org/bouncycastle/asn1/x509/AlgorithmIdentifier.java b/src/org/bouncycastle/asn1/x509/AlgorithmIdentifier.java new file mode 100644 index 0000000..cad4c82 --- /dev/null +++ b/src/org/bouncycastle/asn1/x509/AlgorithmIdentifier.java @@ -0,0 +1,136 @@ +package org.bouncycastle.asn1.x509; + +import java.io.*; +import java.util.Enumeration; + +import org.bouncycastle.asn1.*; + +public class AlgorithmIdentifier + implements DEREncodable +{ + private DERObjectIdentifier objectId; + private DERObject parameters; + private boolean parametersDefined = false; + + public AlgorithmIdentifier( + DERObjectIdentifier objectId) + { + this.objectId = objectId; + } + + public AlgorithmIdentifier( + DERObjectIdentifier objectId, + DERObject parameters) + { + parametersDefined = true; + + this.objectId = objectId; + this.parameters = parameters; + } + + public AlgorithmIdentifier( + DERConstructedSequence obj) + { + objectId = (DERObjectIdentifier)obj.getObjectAt(0); + + if (obj.getSize() == 2) + { + parametersDefined = true; + parameters = (DERObject)obj.getObjectAt(1); + } + else + { + parameters = null; + } + } + + public DERObjectIdentifier getObjectId() + { + return objectId; + } + + public DERObject getParameters() + { + return parameters; + } + + /** + *
+     *      AlgorithmIdentifier ::= SEQUENCE {
+     *                            algorithm OBJECT IDENTIFIER,
+     *                            parameters ANY DEFINED BY algorithm OPTIONAL }
+     * 
+ */ + public DERObject getDERObject() + { + DERConstructedSequence seq = new DERConstructedSequence(); + + seq.addObject(objectId); + + if (parametersDefined) + { + seq.addObject(parameters); + } + + return seq; + } + + public boolean equals( + Object o) + { + if ((o == null) || !(o instanceof AlgorithmIdentifier)) + { + return false; + } + + AlgorithmIdentifier other = (AlgorithmIdentifier)o; + + if (!this.getObjectId().equals(other.getObjectId())) + { + return false; + } + + if (this.getParameters() == null && other.getParameters() == null) + { + return true; + } + + if (this.getParameters() == null || other.getParameters() == null) + { + return false; + } + + ByteArrayOutputStream b1Out = new ByteArrayOutputStream(); + ByteArrayOutputStream b2Out = new ByteArrayOutputStream(); + DEROutputStream d1Out = new DEROutputStream(b1Out); + DEROutputStream d2Out = new DEROutputStream(b2Out); + + try + { + d1Out.writeObject(this.getParameters()); + d2Out.writeObject(other.getParameters()); + + byte[] b1 = b1Out.toByteArray(); + byte[] b2 = b2Out.toByteArray(); + + if (b1.length != b2.length) + { + return false; + } + + for (int i = 0; i != b1.length; i++) + { + if (b1[i] != b2[i]) + { + return false; + } + } + } + catch (Exception e) + { + return false; + } + + return true; + } +}