Sha256: 44ab9ea802d09ea5af9270686c867f406d282121ac8e77ae523aad1a72848003

Contents?: true

Size: 494 Bytes

Versions: 1

Compression:

Stored size: 494 Bytes

Contents

require_relative 'libopenssl'
require_relative 'libc'

module LibNetPGP

  # BIGNUM* to hexadecimal string
  def self.bn2hex(bn)
    str, ptr = LibOpenSSL::BN_bn2hex(bn)
    LibC::free(ptr)
    str
  end

  # Ruby Fixnum to BIGNUM*
  def self.num2bn(num)
    bn_ptr = FFI::MemoryPointer.new(:pointer)
    hex = num.to_s(16)
    ret = LibOpenSSL::BN_hex2bn(bn_ptr, hex)
    raise 'Fixnum to BIGNUM conversion failed' if ret == 0
    bn = bn_ptr.get_pointer(0)
    bn_ptr.free
    bn
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
netpgp-0.0.1 lib/netpgp/lowlevel/utils.rb