/// <summary> /// Parses the signature subpacket given as byte array into /// the current class and returns this with the populated /// parameters. /// </summary> /// <param name="bData">A byte array containing an OpenPGP /// representation of the signature subpacket.</param> /// <returns>Returns an SignatureSubPacket that containes /// the parsed properties.</returns> /// <remarks>No remarks</remarks> public SignatureSubPacket ParsePacket(byte[] bData) { lLength = bData[0]; if (lLength < 192) { bHeader = new byte[2]; bBody = new byte[lLength-1]; Array.Copy(bData, 0, bHeader, 0, 2); Array.Copy(bData, 2, bBody, 0, (int)lLength-1); sptType = (SignatureSubPacketTypes)bData[1]; } else if ((lLength > 191) && (lLength < 255)) { lLength = ((bData[0] - 192) << 8) + bData[1] + 192; bHeader = new byte[3]; bBody = new byte[lLength-1]; Array.Copy(bData, 0, bHeader, 0, 3); Array.Copy(bData, 3, bBody, 0, (int)lLength-1); sptType = (SignatureSubPacketTypes)bData[2]; } else { //lLength == 255 lLength = (bData[1] << 24) ^ (bData[2] << 16) ^ (bData[3] << 8) ^ bData[4]; bHeader = new byte[6]; bBody = new byte[lLength-1]; Array.Copy(bData, 0, bHeader, 0, 6); Array.Copy(bData, 6, bBody, 0, (int)lLength-1); sptType = (SignatureSubPacketTypes)bData[5]; } // TODO: Add Error Handling!!! long iTime = 0; switch (sptType) { case SignatureSubPacketTypes.SignatureCreationTime: iTime = bBody[0] << 24; iTime ^= bBody[1] << 16; iTime ^= bBody[2] << 8; iTime ^= bBody[3]; dtTimeCreated = new DateTime(iTime*10000000 + new DateTime(1970, 1, 1).Ticks); break; case SignatureSubPacketTypes.IssuerKeyID: lKeyID = (ulong)bBody[0] << 56; lKeyID ^= (ulong)bBody[1] << 48; lKeyID ^= (ulong)bBody[2] << 40; lKeyID ^= (ulong)bBody[3] << 32; lKeyID ^= (ulong)bBody[4] << 24; lKeyID ^= (ulong)bBody[5] << 16; lKeyID ^= (ulong)bBody[6] << 8; lKeyID ^= (ulong)bBody[7]; break; case SignatureSubPacketTypes.KeyServerPreferences: kptKeyserverPreferences = new KeyserverPreferencesTypes[bBody.Length]; for (int i=0; i<bBody.Length; i++) this.kptKeyserverPreferences[i] = (KeyserverPreferencesTypes)bBody[i]; break; case SignatureSubPacketTypes.PreferedKeyServer: char[] cKeyserver = new char[bBody.Length]; Array.Copy(bBody, cKeyserver, bBody.Length); strPreferedKeyServer = cKeyserver.ToString(); break; case SignatureSubPacketTypes.TrustSignature: bTrustLevel = bBody[0]; bTrustAmount = bBody[1]; break; case SignatureSubPacketTypes.KeyFlags: kftKeyFlags = new KeyFlagTypes[bBody.Length]; for (int i=0; i<bBody.Length; i++) kftKeyFlags[i] = (KeyFlagTypes)bBody[i]; break; case SignatureSubPacketTypes.KeyExpirationTime: iTime = bBody[0] << 24; iTime ^= bBody[1] << 16; iTime ^= bBody[2] << 8; iTime ^= bBody[3]; dtKeyExpirationTime = new DateTime(iTime*10000000 + new DateTime(1970, 1, 1).Ticks); break; case SignatureSubPacketTypes.SignatureExpirationTime: iTime = bBody[0] << 24; iTime ^= bBody[1] << 16; iTime ^= bBody[2] << 8; iTime ^= bBody[3]; dtSignatureExpirationTime = new DateTime(iTime*10000000 + new DateTime(1970, 1, 1).Ticks); break; case SignatureSubPacketTypes.PreferedSymmetricAlgorithms: saPreferedSymAlgos = new SymAlgorithms[bBody.Length]; for (int i=0; i<bBody.Length; i++) saPreferedSymAlgos[i] = (SymAlgorithms)bBody[i]; break; case SignatureSubPacketTypes.PreferedHashAlgorithms: haPreferedHashAlgorithms = new HashAlgorithms[bBody.Length]; for (int i=0; i<bBody.Length; i++) haPreferedHashAlgorithms[i] = (HashAlgorithms)bBody[i]; break; case SignatureSubPacketTypes.PreferedCompressionAlgorithms: caPreferedCompressionAlgorithms = new CompressionAlgorithms[bBody.Length]; for (int i=0; i<bBody.Length; i++) caPreferedCompressionAlgorithms[i] = (CompressionAlgorithms)bBody[i]; break; case SignatureSubPacketTypes.ExportableSignature: bExportableSignature = (bBody[0] == 1); break; case SignatureSubPacketTypes.Revocable: bRevocable = (bBody[0] == 1); break; case SignatureSubPacketTypes.PrimaryUserID: bPrimaryUserID = (bBody[0] == 1); break; case SignatureSubPacketTypes.RevocationKey: this.Sensible = (bBody[1] >> 3) & 0x01; this.FingerprintHash = (HashAlgorithms)bBody[1]; byte[] fingerprint = new byte[bBody.Length-2]; for(int i = 2; i < bBody.Length; i++) fingerprint[i-2] = bBody[i]; this.RevocationKeyID = new BigInteger(fingerprint); break; case SignatureSubPacketTypes.ReasonForRevocation: byte[] reason = new byte[bBody.Length-1]; for(int i = 1; i < bBody.Length; i++) reason[i-1] = bBody[i]; this.ReasonForRevocationCode = bBody[0]; char [] reasArray = new char[reason.Length]; Array.Copy(reason,reasArray,reason.Length); this.ReasonForRevocation = new string(reasArray); break; case SignatureSubPacketTypes.NotationData: int nameLength = bBody[4] << 8; nameLength ^= bBody[5]; int valueLength = bBody[6] << 8; valueLength ^= bBody[7]; byte[] name = new byte[nameLength]; byte[] val = new byte[valueLength]; for(int i = 8; i < nameLength + 8; i++) name[i-8] = bBody[i]; for(int i = nameLength + 8; i < valueLength + nameLength + 8; i++) val[i-nameLength-8] = bBody[i]; char [] notnamArray = new char[nameLength]; Array.Copy(name,notnamArray,name.Length); this.NotationName = new string(notnamArray); char [] notvalArray = new char[valueLength]; Array.Copy(val,notvalArray,val.Length); this.NotationValue = new string(notvalArray); break; } return this; }
/// <summary> /// Parses the signature subpacket given as byte array into /// the current class and returns this with the populated /// parameters. /// </summary> /// <param name="bData">A byte array containing an OpenPGP /// representation of the signature subpacket.</param> /// <returns>Returns an SignatureSubPacket that containes /// the parsed properties.</returns> /// <remarks>No remarks</remarks> public SignatureSubPacket ParsePacket(byte[] bData) { lLength = bData[0]; if (lLength < 192) { bHeader = new byte[2]; bBody = new byte[lLength - 1]; Array.Copy(bData, 0, bHeader, 0, 2); Array.Copy(bData, 2, bBody, 0, (int)lLength - 1); sptType = (SignatureSubPacketTypes)bData[1]; } else if ((lLength > 191) && (lLength < 255)) { lLength = ((bData[0] - 192) << 8) + bData[1] + 192; bHeader = new byte[3]; bBody = new byte[lLength - 1]; Array.Copy(bData, 0, bHeader, 0, 3); Array.Copy(bData, 3, bBody, 0, (int)lLength - 1); sptType = (SignatureSubPacketTypes)bData[2]; } else //lLength == 255 { lLength = (bData[1] << 24) ^ (bData[2] << 16) ^ (bData[3] << 8) ^ bData[4]; bHeader = new byte[6]; bBody = new byte[lLength - 1]; Array.Copy(bData, 0, bHeader, 0, 6); Array.Copy(bData, 6, bBody, 0, (int)lLength - 1); sptType = (SignatureSubPacketTypes)bData[5]; } // TODO: Add Error Handling!!! long iTime = 0; switch (sptType) { case SignatureSubPacketTypes.SignatureCreationTime: iTime = bBody[0] << 24; iTime ^= bBody[1] << 16; iTime ^= bBody[2] << 8; iTime ^= bBody[3]; dtTimeCreated = new DateTime(iTime * 10000000 + new DateTime(1970, 1, 1).Ticks); break; case SignatureSubPacketTypes.IssuerKeyID: lKeyID = (ulong)bBody[0] << 56; lKeyID ^= (ulong)bBody[1] << 48; lKeyID ^= (ulong)bBody[2] << 40; lKeyID ^= (ulong)bBody[3] << 32; lKeyID ^= (ulong)bBody[4] << 24; lKeyID ^= (ulong)bBody[5] << 16; lKeyID ^= (ulong)bBody[6] << 8; lKeyID ^= (ulong)bBody[7]; break; case SignatureSubPacketTypes.KeyServerPreferences: kptKeyserverPreferences = new KeyserverPreferencesTypes[bBody.Length]; for (int i = 0; i < bBody.Length; i++) { this.kptKeyserverPreferences[i] = (KeyserverPreferencesTypes)bBody[i]; } break; case SignatureSubPacketTypes.PreferedKeyServer: char[] cKeyserver = new char[bBody.Length]; Array.Copy(bBody, cKeyserver, bBody.Length); strPreferedKeyServer = cKeyserver.ToString(); break; case SignatureSubPacketTypes.TrustSignature: bTrustLevel = bBody[0]; bTrustAmount = bBody[1]; break; case SignatureSubPacketTypes.KeyFlags: kftKeyFlags = new KeyFlagTypes[bBody.Length]; for (int i = 0; i < bBody.Length; i++) { kftKeyFlags[i] = (KeyFlagTypes)bBody[i]; } break; case SignatureSubPacketTypes.KeyExpirationTime: iTime = bBody[0] << 24; iTime ^= bBody[1] << 16; iTime ^= bBody[2] << 8; iTime ^= bBody[3]; dtKeyExpirationTime = new DateTime(iTime * 10000000 + new DateTime(1970, 1, 1).Ticks); break; case SignatureSubPacketTypes.SignatureExpirationTime: iTime = bBody[0] << 24; iTime ^= bBody[1] << 16; iTime ^= bBody[2] << 8; iTime ^= bBody[3]; dtSignatureExpirationTime = new DateTime(iTime * 10000000 + new DateTime(1970, 1, 1).Ticks); break; case SignatureSubPacketTypes.PreferedSymmetricAlgorithms: saPreferedSymAlgos = new SymAlgorithms[bBody.Length]; for (int i = 0; i < bBody.Length; i++) { saPreferedSymAlgos[i] = (SymAlgorithms)bBody[i]; } break; case SignatureSubPacketTypes.PreferedHashAlgorithms: haPreferedHashAlgorithms = new HashAlgorithms[bBody.Length]; for (int i = 0; i < bBody.Length; i++) { haPreferedHashAlgorithms[i] = (HashAlgorithms)bBody[i]; } break; case SignatureSubPacketTypes.PreferedCompressionAlgorithms: caPreferedCompressionAlgorithms = new CompressionAlgorithms[bBody.Length]; for (int i = 0; i < bBody.Length; i++) { caPreferedCompressionAlgorithms[i] = (CompressionAlgorithms)bBody[i]; } break; case SignatureSubPacketTypes.ExportableSignature: bExportableSignature = (bBody[0] == 1); break; case SignatureSubPacketTypes.Revocable: bRevocable = (bBody[0] == 1); break; case SignatureSubPacketTypes.PrimaryUserID: bPrimaryUserID = (bBody[0] == 1); break; } return(this); }
/// <summary> /// Parses the signature subpacket given as byte array into /// the current class and returns this with the populated /// parameters. /// </summary> /// <param name="bData">A byte array containing an OpenPGP /// representation of the signature subpacket.</param> /// <returns>Returns an SignatureSubPacket that containes /// the parsed properties.</returns> /// <remarks>No remarks</remarks> public SignatureSubPacket ParsePacket(byte[] bData) { lLength = bData[0]; if (lLength < 192) { bHeader = new byte[2]; bBody = new byte[lLength - 1]; Array.Copy(bData, 0, bHeader, 0, 2); Array.Copy(bData, 2, bBody, 0, (int)lLength - 1); sptType = (SignatureSubPacketTypes)bData[1]; } else if ((lLength > 191) && (lLength < 255)) { lLength = ((bData[0] - 192) << 8) + bData[1] + 192; bHeader = new byte[3]; bBody = new byte[lLength - 1]; Array.Copy(bData, 0, bHeader, 0, 3); Array.Copy(bData, 3, bBody, 0, (int)lLength - 1); sptType = (SignatureSubPacketTypes)bData[2]; } else //lLength == 255 { lLength = (bData[1] << 24) ^ (bData[2] << 16) ^ (bData[3] << 8) ^ bData[4]; bHeader = new byte[6]; bBody = new byte[lLength - 1]; Array.Copy(bData, 0, bHeader, 0, 6); Array.Copy(bData, 6, bBody, 0, (int)lLength - 1); sptType = (SignatureSubPacketTypes)bData[5]; } // TODO: Add Error Handling!!! long iTime = 0; switch (sptType) { case SignatureSubPacketTypes.SignatureCreationTime: iTime = bBody[0] << 24; iTime ^= bBody[1] << 16; iTime ^= bBody[2] << 8; iTime ^= bBody[3]; dtTimeCreated = new DateTime(iTime * 10000000 + new DateTime(1970, 1, 1).Ticks); break; case SignatureSubPacketTypes.IssuerKeyID: lKeyID = (ulong)bBody[0] << 56; lKeyID ^= (ulong)bBody[1] << 48; lKeyID ^= (ulong)bBody[2] << 40; lKeyID ^= (ulong)bBody[3] << 32; lKeyID ^= (ulong)bBody[4] << 24; lKeyID ^= (ulong)bBody[5] << 16; lKeyID ^= (ulong)bBody[6] << 8; lKeyID ^= (ulong)bBody[7]; break; case SignatureSubPacketTypes.KeyServerPreferences: kptKeyserverPreferences = new KeyserverPreferencesTypes[bBody.Length]; for (int i = 0; i < bBody.Length; i++) { this.kptKeyserverPreferences[i] = (KeyserverPreferencesTypes)bBody[i]; } break; case SignatureSubPacketTypes.PreferedKeyServer: char[] cKeyserver = new char[bBody.Length]; Array.Copy(bBody, cKeyserver, bBody.Length); strPreferedKeyServer = cKeyserver.ToString(); break; case SignatureSubPacketTypes.TrustSignature: bTrustLevel = bBody[0]; bTrustAmount = bBody[1]; break; case SignatureSubPacketTypes.KeyFlags: kftKeyFlags = new KeyFlagTypes[bBody.Length]; for (int i = 0; i < bBody.Length; i++) { kftKeyFlags[i] = (KeyFlagTypes)bBody[i]; } break; case SignatureSubPacketTypes.KeyExpirationTime: iTime = bBody[0] << 24; iTime ^= bBody[1] << 16; iTime ^= bBody[2] << 8; iTime ^= bBody[3]; dtKeyExpirationTime = new DateTime(iTime * 10000000 + new DateTime(1970, 1, 1).Ticks); break; case SignatureSubPacketTypes.SignatureExpirationTime: iTime = bBody[0] << 24; iTime ^= bBody[1] << 16; iTime ^= bBody[2] << 8; iTime ^= bBody[3]; dtSignatureExpirationTime = new DateTime(iTime * 10000000 + new DateTime(1970, 1, 1).Ticks); break; case SignatureSubPacketTypes.PreferedSymmetricAlgorithms: saPreferedSymAlgos = new SymAlgorithms[bBody.Length]; for (int i = 0; i < bBody.Length; i++) { saPreferedSymAlgos[i] = (SymAlgorithms)bBody[i]; } break; case SignatureSubPacketTypes.PreferedHashAlgorithms: haPreferedHashAlgorithms = new HashAlgorithms[bBody.Length]; for (int i = 0; i < bBody.Length; i++) { haPreferedHashAlgorithms[i] = (HashAlgorithms)bBody[i]; } break; case SignatureSubPacketTypes.PreferedCompressionAlgorithms: caPreferedCompressionAlgorithms = new CompressionAlgorithms[bBody.Length]; for (int i = 0; i < bBody.Length; i++) { caPreferedCompressionAlgorithms[i] = (CompressionAlgorithms)bBody[i]; } break; case SignatureSubPacketTypes.ExportableSignature: bExportableSignature = (bBody[0] == 1); break; case SignatureSubPacketTypes.Revocable: bRevocable = (bBody[0] == 1); break; case SignatureSubPacketTypes.PrimaryUserID: bPrimaryUserID = (bBody[0] == 1); break; case SignatureSubPacketTypes.RevocationKey: this.Sensible = (bBody[1] >> 3) & 0x01; this.FingerprintHash = (HashAlgorithms)bBody[1]; byte[] fingerprint = new byte[bBody.Length - 2]; for (int i = 2; i < bBody.Length; i++) { fingerprint[i - 2] = bBody[i]; } this.RevocationKeyID = new BigInteger(fingerprint); break; case SignatureSubPacketTypes.ReasonForRevocation: byte[] reason = new byte[bBody.Length - 1]; for (int i = 1; i < bBody.Length; i++) { reason[i - 1] = bBody[i]; } this.ReasonForRevocationCode = bBody[0]; char [] reasArray = new char[reason.Length]; Array.Copy(reason, reasArray, reason.Length); this.ReasonForRevocation = new string(reasArray); break; case SignatureSubPacketTypes.NotationData: int nameLength = bBody[4] << 8; nameLength ^= bBody[5]; int valueLength = bBody[6] << 8; valueLength ^= bBody[7]; byte[] name = new byte[nameLength]; byte[] val = new byte[valueLength]; for (int i = 8; i < nameLength + 8; i++) { name[i - 8] = bBody[i]; } for (int i = nameLength + 8; i < valueLength + nameLength + 8; i++) { val[i - nameLength - 8] = bBody[i]; } char [] notnamArray = new char[nameLength]; Array.Copy(name, notnamArray, name.Length); this.NotationName = new string(notnamArray); char [] notvalArray = new char[valueLength]; Array.Copy(val, notvalArray, val.Length); this.NotationValue = new string(notvalArray); break; } return(this); }