Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/java/org/spongycastle/asn1/x9/KeySpecificInfo.java')
-rw-r--r--core/src/main/java/org/spongycastle/asn1/x9/KeySpecificInfo.java68
1 files changed, 68 insertions, 0 deletions
diff --git a/core/src/main/java/org/spongycastle/asn1/x9/KeySpecificInfo.java b/core/src/main/java/org/spongycastle/asn1/x9/KeySpecificInfo.java
new file mode 100644
index 00000000..3a7f9517
--- /dev/null
+++ b/core/src/main/java/org/spongycastle/asn1/x9/KeySpecificInfo.java
@@ -0,0 +1,68 @@
+package org.spongycastle.asn1.x9;
+
+import java.util.Enumeration;
+
+import org.spongycastle.asn1.ASN1EncodableVector;
+import org.spongycastle.asn1.ASN1Object;
+import org.spongycastle.asn1.ASN1ObjectIdentifier;
+import org.spongycastle.asn1.ASN1OctetString;
+import org.spongycastle.asn1.ASN1Primitive;
+import org.spongycastle.asn1.ASN1Sequence;
+import org.spongycastle.asn1.DERSequence;
+
+/**
+ * ASN.1 def for Diffie-Hellman key exchange KeySpecificInfo structure. See
+ * RFC 2631, or X9.42, for further details.
+ */
+public class KeySpecificInfo
+ extends ASN1Object
+{
+ private ASN1ObjectIdentifier algorithm;
+ private ASN1OctetString counter;
+
+ public KeySpecificInfo(
+ ASN1ObjectIdentifier algorithm,
+ ASN1OctetString counter)
+ {
+ this.algorithm = algorithm;
+ this.counter = counter;
+ }
+
+ public KeySpecificInfo(
+ ASN1Sequence seq)
+ {
+ Enumeration e = seq.getObjects();
+
+ algorithm = (ASN1ObjectIdentifier)e.nextElement();
+ counter = (ASN1OctetString)e.nextElement();
+ }
+
+ public ASN1ObjectIdentifier getAlgorithm()
+ {
+ return algorithm;
+ }
+
+ public ASN1OctetString getCounter()
+ {
+ return counter;
+ }
+
+ /**
+ * Produce an object suitable for an ASN1OutputStream.
+ * <pre>
+ * KeySpecificInfo ::= SEQUENCE {
+ * algorithm OBJECT IDENTIFIER,
+ * counter OCTET STRING SIZE (4..4)
+ * }
+ * </pre>
+ */
+ public ASN1Primitive toASN1Primitive()
+ {
+ ASN1EncodableVector v = new ASN1EncodableVector();
+
+ v.add(algorithm);
+ v.add(counter);
+
+ return new DERSequence(v);
+ }
+}