public static byte[] EncodeSignature(ECDSA_SIG signature) { byte[] result; using (var ms = new MemoryStream()) { StreamOp.WriteBytes(ms, ref signature.R); StreamOp.WriteBytes(ms, ref signature.S); result = StreamOp.SaveStreamToRaw(ms); } return(result); }
public static bool DecodeSignature(byte[] rawSignature, out ECDSA_SIG signature) { signature = CT_TECDSA_SIG_Nul; using (var ms = new MemoryStream()) { StreamOp.LoadStreamFromRaw(ms, rawSignature); ms.Position = 0; if (StreamOp.ReadBytes(ms, ref signature.R) < 0) { return(false); } if (StreamOp.ReadBytes(ms, ref signature.S) < 0) { return(false); } if (ms.Position < ms.Length) { return(false); // Invalid position } } return(true); }
internal static void ToSerialized(ref byte[] result, Stream stream) => StreamOp.WriteBytes(stream, ref result);
internal static int FromSerialized(ref byte[] result, Stream stream, int checkLength = 0) => StreamOp.ReadBytes(stream, ref result, checkLength);