/// <summary> /// Register a new IPFS hashing algorithm. /// </summary> /// <param name="name"> /// The name of the algorithm. /// </param> /// <param name="code"> /// The IPFS number assigned to the hashing algorithm. /// </param> /// <param name="digestSize"> /// The size, in bytes, of the digest value. /// </param> /// <param name="hasher"> /// A <c>Func</c> that returns a <see cref="HashAlgorithm"/>. If not specified, then a <c>Func</c> is created to /// throw a <see cref="NotImplementedException"/>. /// </param> /// <returns> /// A new <see cref="HashingAlgorithm"/>. /// </returns> public static HashingAlgorithm Register(string name, int code, int digestSize, Func <HashAlgorithm> hasher = null) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } if (Names.ContainsKey(name)) { throw new ArgumentException(string.Format("The IPFS hashing algorithm '{0}' is already defined.", name)); } if (Codes.ContainsKey(code)) { throw new ArgumentException( $"The IPFS hashing algorithm code 0x{code:x2} is already defined."); } if (hasher == null) { hasher = () => throw new NotImplementedException( $"The IPFS hashing algorithm '{name}' is not implemented."); } var a = new HashingAlgorithm { Name = name, Code = code, DigestSize = digestSize, Hasher = hasher }; Names[name] = a; Codes[code] = a; return(a); }
/// <summary> /// Remove an IPFS hashing algorithm from the registry. /// </summary> /// <param name="algorithm"> /// The <see cref="HashingAlgorithm"/> to remove. /// </param> public static void DeRegister(HashingAlgorithm algorithm) { Names.Remove(algorithm.Name); Codes.Remove(algorithm.Code); }