public static (Hash, Signature) GetHashAndSignature(this Unpacker unpacker, int dataOffset, int dataSize) { var signatureKeyType = (KeyTypes)unpacker.UnpackByte(); unpacker.Position--; var signatureSize = Signature.GetSignatureBytes(signatureKeyType); unpacker.Unpack(out byte[] signatureData, signatureSize); var position = unpacker.Position; var signature = Signature.Restore(new ArraySegment <byte>(signatureData)); var partialStream = new PartialStream(unpacker.Stream, dataOffset, dataSize); var signatureHash = Hash.Generate(signature.DataHashType, partialStream); unpacker.Position = position; return(signatureHash, signature); }
public static (Hash, Signature) AddSignature(this Packer packer, Key signKey, int dataOffset, int dataSize) { if (!signKey.IsPrivate) { throw new ArgumentException("Key is not private", nameof(signKey)); } var partialStream = new PartialStream(packer.Stream, dataOffset, dataSize); var hash = Hash.Generate(Protocol.MessageHashType, partialStream); var signature = Signature.Generate(signKey, hash); var signature2 = Signature.Generate(signKey, hash); if (signature != signature2) { throw new Exception("Invalid signature computation"); } Pack(packer, signature); return(hash, signature); }