/// <summary> /// Parses the specified hexadecimal. /// </summary> /// <param name="hex">The hexadecimal.</param> /// <returns></returns> /// <exception cref="FormatException">Sha1</exception> public static Sha1 Parse(ReadOnlySpan <char> hex) { Span <byte> sha = stackalloc byte[ByteLength]; if (!ShaUtil.TryParse(hex, sha)) { throw new FormatException($"Input was not recognized as a valid {nameof(Sha1)}"); } var value = new Sha1(sha); return(value); }
/// <summary> /// Tries to parse the specified hexadecimal. /// </summary> /// <param name="hex">The hexadecimal.</param> /// <param name="value">The value.</param> /// <returns></returns> public static bool TryParse(ReadOnlySpan <char> hex, out Sha1 value) { value = default; Span <byte> sha = stackalloc byte[ByteLength]; if (!ShaUtil.TryParse(hex, sha)) { return(false); } value = new Sha1(sha); return(true); }
/// <summary> /// Tries to parse the specified hexadecimal. /// </summary> /// <param name="hex">The hexadecimal.</param> /// <param name="value">The value.</param> /// <returns></returns> public static bool TryParse(string hex, out Sha1 value) { value = default; if (hex is null || hex.Length < HexLength) { return(false); } Span <byte> sha = stackalloc byte[ByteLength]; if (!ShaUtil.TryParse(hex.AsSpan(), sha)) { return(false); } value = new Sha1(sha); return(true); }
/// <summary> /// Parses the specified hexadecimal. /// </summary> /// <param name="hex">The hexadecimal.</param> /// <returns></returns> /// <exception cref="FormatException">Sha1</exception> public static Sha1 Parse(string hex) { if (hex is null) { throw new ArgumentNullException(nameof(hex)); } if (hex.Length < HexLength) { throw new FormatException($"Input was not recognized as a valid {nameof(Sha1)}"); } Span <byte> sha = stackalloc byte[ByteLength]; if (!ShaUtil.TryParse(hex.AsSpan(), sha)) { throw new FormatException($"Input was not recognized as a valid {nameof(Sha1)}"); } var value = new Sha1(sha); return(value); }