summaryrefslogtreecommitdiff
path: root/bcpkix/src/main/java/org/bouncycastle/cert/cmp/GeneralPKIMessage.java
diff options
context:
space:
mode:
authorSergio Giro <sgiro@google.com>2015-12-11 18:58:58 +0000
committerSergio Giro <sgiro@google.com>2016-01-25 15:38:49 +0000
commit16f9ee464b68937f45d009d9c1b0eb9b544a8dee (patch)
tree61086f6673133c387b13b0e494e42973c6f4c0e8 /bcpkix/src/main/java/org/bouncycastle/cert/cmp/GeneralPKIMessage.java
parentfcfe48e7cf461bf4a6314802c0f31f292d87ab95 (diff)
downloadbouncycastle-16f9ee464b68937f45d009d9c1b0eb9b544a8dee.tar.gz
bouncycastle: Android tree with upstream code for version 1.49
Android tree as of 08e455bd61ddaa02255383e85480b0d9cde6e954 Change-Id: I99dab80b49707f0fdefb67ccd1bcfe765363b5e5
Diffstat (limited to 'bcpkix/src/main/java/org/bouncycastle/cert/cmp/GeneralPKIMessage.java')
-rw-r--r--bcpkix/src/main/java/org/bouncycastle/cert/cmp/GeneralPKIMessage.java82
1 files changed, 82 insertions, 0 deletions
diff --git a/bcpkix/src/main/java/org/bouncycastle/cert/cmp/GeneralPKIMessage.java b/bcpkix/src/main/java/org/bouncycastle/cert/cmp/GeneralPKIMessage.java
new file mode 100644
index 00000000..a928623f
--- /dev/null
+++ b/bcpkix/src/main/java/org/bouncycastle/cert/cmp/GeneralPKIMessage.java
@@ -0,0 +1,82 @@
+package org.bouncycastle.cert.cmp;
+
+import java.io.IOException;
+
+import org.bouncycastle.asn1.ASN1Primitive;
+import org.bouncycastle.asn1.cmp.PKIBody;
+import org.bouncycastle.asn1.cmp.PKIHeader;
+import org.bouncycastle.asn1.cmp.PKIMessage;
+import org.bouncycastle.cert.CertIOException;
+
+/**
+ * General wrapper for a generic PKIMessage
+ */
+public class GeneralPKIMessage
+{
+ private final PKIMessage pkiMessage;
+
+ private static PKIMessage parseBytes(byte[] encoding)
+ throws IOException
+ {
+ try
+ {
+ return PKIMessage.getInstance(ASN1Primitive.fromByteArray(encoding));
+ }
+ catch (ClassCastException e)
+ {
+ throw new CertIOException("malformed data: " + e.getMessage(), e);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new CertIOException("malformed data: " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Create a PKIMessage from the passed in bytes.
+ *
+ * @param encoding BER/DER encoding of the PKIMessage
+ * @throws IOException in the event of corrupted data, or an incorrect structure.
+ */
+ public GeneralPKIMessage(byte[] encoding)
+ throws IOException
+ {
+ this(parseBytes(encoding));
+ }
+
+ /**
+ * Wrap a PKIMessage ASN.1 structure.
+ *
+ * @param pkiMessage base PKI message.
+ */
+ public GeneralPKIMessage(PKIMessage pkiMessage)
+ {
+ this.pkiMessage = pkiMessage;
+ }
+
+ public PKIHeader getHeader()
+ {
+ return pkiMessage.getHeader();
+ }
+
+ public PKIBody getBody()
+ {
+ return pkiMessage.getBody();
+ }
+
+ /**
+ * Return true if this message has protection bits on it. A return value of true
+ * indicates the message can be used to construct a ProtectedPKIMessage.
+ *
+ * @return true if message has protection, false otherwise.
+ */
+ public boolean hasProtection()
+ {
+ return pkiMessage.getHeader().getProtectionAlg() != null;
+ }
+
+ public PKIMessage toASN1Structure()
+ {
+ return pkiMessage;
+ }
+}