summary refs log tree commit diff
path: root/crypto/src/bcpg/UserIdPacket.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-02-28 18:49:21 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-02-28 18:49:21 +0700
commit5ac39b19f346e72005f41f13ff956f4fa7c97f86 (patch)
tree0ca4585a968a8b11044267b0268d3e65f29fa559 /crypto/src/bcpg/UserIdPacket.cs
parentUpdate Asn1Tags (diff)
downloadBouncyCastle.NET-ed25519-5ac39b19f346e72005f41f13ff956f4fa7c97f86.tar.xz
OpenPGP updates from bc-java
Diffstat (limited to 'crypto/src/bcpg/UserIdPacket.cs')
-rw-r--r--crypto/src/bcpg/UserIdPacket.cs37
1 files changed, 28 insertions, 9 deletions
diff --git a/crypto/src/bcpg/UserIdPacket.cs b/crypto/src/bcpg/UserIdPacket.cs
index a175e74a6..7d3d3a846 100644
--- a/crypto/src/bcpg/UserIdPacket.cs
+++ b/crypto/src/bcpg/UserIdPacket.cs
@@ -1,37 +1,56 @@
 using System;
 using System.Text;
 
+using Org.BouncyCastle.Utilities;
+
 namespace Org.BouncyCastle.Bcpg
 {
     /**
     * Basic type for a user ID packet.
     */
     public class UserIdPacket
-        : ContainedPacket
+        : ContainedPacket, IUserDataPacket
     {
         private readonly byte[] idData;
 
-        public UserIdPacket(
-            BcpgInputStream bcpgIn)
+        public UserIdPacket(BcpgInputStream bcpgIn)
         {
             this.idData = bcpgIn.ReadAll();
         }
 
-		public UserIdPacket(
-			string id)
+		public UserIdPacket(string id)
         {
             this.idData = Encoding.UTF8.GetBytes(id);
         }
 
-		public string GetId()
+        public UserIdPacket(byte[] rawId)
+        {
+            this.idData = Arrays.Clone(rawId);
+        }
+
+        public string GetId()
         {
 			return Encoding.UTF8.GetString(idData, 0, idData.Length);
         }
 
-		public override void Encode(
-            BcpgOutputStream bcpgOut)
+        public byte[] GetRawId() => Arrays.Clone(idData);
+
+        public override bool Equals(object obj)
+        {
+            if (!(obj is UserIdPacket other))
+                return false;
+
+            return Arrays.AreEqual(this.idData, other.idData);
+        }
+
+        public override int GetHashCode()
+        {
+            return Arrays.GetHashCode(this.idData);
+        }
+
+        public override void Encode(BcpgOutputStream bcpgOut)
         {
-            bcpgOut.WritePacket(PacketTag.UserId, idData, true);
+            bcpgOut.WritePacket(PacketTag.UserId, idData);
         }
     }
 }