/// <summary>
        /// Creates a <see cref="SecureBigNumber" /> instance from a valid <see cref="BigNumberHandle" />
        /// to a secure OpenSSL <c>BIGNUM</c> structure. A copy of the pointed to <c>BIGNUM</c> structure
        /// is made for the created instance.
        /// </summary>
        /// <param name="bigNumberHandle">
        /// A handle to a raw OpenSSL <c>BIGNUM</c> structure with which to initialize the new <see cref="SecureBigNumber" />.
        /// </param>
        /// <returns>
        /// A new <see cref="SecureBigNumber" /> instance with the same value as
        /// referred to by <paramref name="bigNumberHandle"/>.
        /// </returns>
        internal static SecureBigNumber FromRawHandle(BigNumberHandle bigNumberHandle)
        {
            if (bigNumberHandle.IsInvalid)
            {
                throw new ArgumentException("The provided handle is invalid.", nameof(bigNumberHandle));
            }
            var bn = new SecureBigNumber();

            BigNumberHandle.Copy(bn.Handle, bigNumberHandle);
            return(bn);
        }
예제 #2
0
        /// <summary>
        /// Creates a <see cref="BigNumber" /> instance from a valid <see cref="BigNumberHandle" />
        /// to an OpenSSL <c>BIGNUM</c> structure. A copy of the pointed to <c>BIGNUM</c> structure
        /// is made for the created instance.
        /// </summary>
        /// <param name="bigNumberHandle">
        /// A handle to a raw OpenSSL <c>BIGNUM</c> structure with which to initialize the new <see cref="BigNumber" />.
        /// </param>
        /// <returns>
        /// A new <see cref="BigNumber" /> instance with the same value as
        /// referred to by <paramref name="bigNumberHandle"/>.
        /// </returns>
        internal static BigNumber FromRawHandle(BigNumberHandle bigNumberHandle)
        {
            if (bigNumberHandle.IsInvalid)
            {
                throw new ArgumentException("The provided handle is invalid.", nameof(bigNumberHandle));
            }
            if (BigNumberHandle.GetFlags(bigNumberHandle).HasFlag(BigNumberFlags.Secure))
            {
                throw new ArgumentException(
                          "The provided handle is that of a secure big number. Converting secure into regular big numbers is not supported.",
                          nameof(bigNumberHandle)
                          );
            }
            var bn = new BigNumber();

            BigNumberHandle.Copy(bn.Handle, bigNumberHandle);
            return(bn);
        }