summary refs log tree commit diff
path: root/crypto/src/bcpg
diff options
context:
space:
mode:
authorDavid Hook <dgh@bouncycastle.org>2021-05-23 13:28:45 +1000
committerDavid Hook <dgh@bouncycastle.org>2021-05-23 13:28:45 +1000
commitf7d837b990cf19d3b324c7238eace45eb8c5d6bf (patch)
treec1b71240a688b4dcd3c237c4d2add9f091b33a97 /crypto/src/bcpg
parentgithub #296 TSP fix (diff)
downloadBouncyCastle.NET-ed25519-f7d837b990cf19d3b324c7238eace45eb8c5d6bf.tar.xz
github #283 added extra features fields, corrected parsing for new draft
Diffstat (limited to 'crypto/src/bcpg')
-rw-r--r--crypto/src/bcpg/sig/Features.cs62
1 files changed, 26 insertions, 36 deletions
diff --git a/crypto/src/bcpg/sig/Features.cs b/crypto/src/bcpg/sig/Features.cs
index 29584239a..135d7f54e 100644
--- a/crypto/src/bcpg/sig/Features.cs
+++ b/crypto/src/bcpg/sig/Features.cs
@@ -10,25 +10,40 @@ namespace Org.BouncyCastle.Bcpg.Sig
     public class Features
         : SignatureSubpacket
     {
-        /** Identifier for the modification detection feature */
-        public static readonly byte FEATURE_MODIFICATION_DETECTION = 1;
+        /** Identifier for the Modification Detection (packets 18 and 19) */
+        public static readonly byte FEATURE_MODIFICATION_DETECTION = 0x01;
+        /** Identifier for the AEAD Encrypted Data Packet (packet 20) and version 5
+         Symmetric-Key Encrypted Session Key Packets (packet 3) */
+        public static readonly byte FEATURE_AEAD_ENCRYPTED_DATA = 0x02;
+        /** Identifier for the Version 5 Public-Key Packet format and corresponding new
+           fingerprint format */
+        public static readonly byte FEATURE_VERSION_5_PUBLIC_KEY = 0x04;
 
-        private static byte[] FeatureToByteArray(byte feature)
+        private static byte[] featureToByteArray(byte feature)
         {
-            return new byte[]{ feature };
+            byte[] data = new byte[1];
+            data[0] = feature;
+            return data;
         }
 
         public Features(
-            bool    critical,
-            bool    isLongLength,
-            byte[]  data)
-            : base(SignatureSubpacketTag.Features, critical, isLongLength, data)
+            bool critical,
+            bool isLongLength,
+            byte[] data): base(SignatureSubpacketTag.Features, critical, isLongLength, data)
         {
+
+        }
+      
+
+        public Features(bool critical, byte features): this(critical, false, featureToByteArray(features))
+        {
+
         }
+   
 
-        public Features(bool critical, byte feature)
-            : base(SignatureSubpacketTag.Features, critical, false, FeatureToByteArray(feature))
+        public Features(bool critical, int features):  this(critical, false, featureToByteArray((byte)features))
         {
+           
         }
 
         /**
@@ -44,32 +59,7 @@ namespace Org.BouncyCastle.Bcpg.Sig
          */
         public bool SupportsFeature(byte feature)
         {
-            return Array.IndexOf(data, feature) >= 0;
-        }
-
-        /**
-         * Sets support for a particular feature.
-         */
-        private void SetSupportsFeature(byte feature, bool support)
-        {
-            if (feature == 0)
-                throw new ArgumentException("cannot be 0", "feature");
-
-            int i = Array.IndexOf(data, feature);
-            if ((i >= 0) == support)
-                return;
-
-            if (support)
-            {
-                data = Arrays.Append(data, feature);
-            }
-            else
-            {
-                byte[] temp = new byte[data.Length - 1];
-                Array.Copy(data, 0, temp, 0, i);
-                Array.Copy(data, i + 1, temp, i, temp.Length - i);
-                data = temp;
-            }
+            return (data[0] & feature) != 0;
         }
     }
 }