Example #1
0
        /// <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);
        }
Example #2
0
        /// <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);
        }
Example #3
0
        /// <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);
        }
Example #4
0
        /// <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);
        }