Class: BTC::OpenSSL::AutoreleasePool

Inherits:
Object
  • Object
show all
Defined in:
lib/btcruby/openssl.rb

Constant Summary collapse

LIB =
BTC::OpenSSL

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAutoreleasePool

Returns a new instance of AutoreleasePool.



498
499
500
501
502
# File 'lib/btcruby/openssl.rb', line 498

def initialize
  @ec_keys   = []
  @bns       = []
  @ec_points = []
end

Instance Attribute Details

#bn_ctxObject (readonly)

Returns current BN_CTX object or creates one on the fly.



496
497
498
# File 'lib/btcruby/openssl.rb', line 496

def bn_ctx
  @bn_ctx
end

#ec_keyObject (readonly)

Returns last created EC_KEY or creates one on the fly.



493
494
495
# File 'lib/btcruby/openssl.rb', line 493

def ec_key
  @ec_key
end

Instance Method Details

#drainObject



536
537
538
539
540
541
542
543
544
545
# File 'lib/btcruby/openssl.rb', line 536

def drain
  @ec_keys.each   {|eckey| LIB.EC_KEY_free(eckey) }; @ec_keys   = nil
  @bns.each       {|bn|    LIB.BN_free(bn)        }; @bns       = nil
  @ec_points.each {|p|     LIB.EC_POINT_free(p)   }; @ec_points = nil
  if @bn_ctx
    LIB.BN_CTX_free(@bn_ctx)
    @bn_ctx = nil
  end
  return nil
end

#new_bn(data = nil) ⇒ Object

Creates new bignum object optionally initialized with binary data (bin2bn)



519
520
521
522
523
524
525
526
527
528
# File 'lib/btcruby/openssl.rb', line 519

def new_bn(data = nil)
  bn = LIB.BN_new()
  if data && data.size > 0
    data_ptr = FFI::MemoryPointer.from_string(data)
    # size-1 to skip \0 terminator
    bn = LIB.BN_bin2bn(data_ptr, data_ptr.size - 1, bn)
  end
  @bns << bn
  return bn
end

#new_ec_keyObject



512
513
514
515
516
# File 'lib/btcruby/openssl.rb', line 512

def new_ec_key
  eckey = LIB.EC_KEY_new_by_curve_name(NID_secp256k1)
  @ec_keys << eckey
  return eckey
end

#new_ec_pointObject



530
531
532
533
534
# File 'lib/btcruby/openssl.rb', line 530

def new_ec_point
  p = LIB.EC_POINT_new(LIB.group)
  @ec_points << p
  return p
end