Class: Ccrypto::Ruby::RSAKeyBundle

Inherits:
Object
  • Object
show all
Includes:
Ccrypto::RSAKeyBundle, PEMStore, PKCS12Store, TR::CondUtils, TeLogger::TeLogHelper
Defined in:
lib/ccrypto/ruby/engines/rsa_engine.rb

Overview

RSAPublicKey

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PEMStore

included, #to_pem

Methods included from DataConversion

#from_b64, #from_hex, included, #to_b64, #to_hex, #to_int_array

Methods included from PKCS12Store

included, #to_pkcs12

Constructor Details

#initialize(kp) ⇒ RSAKeyBundle

Returns a new instance of RSAKeyBundle.



32
33
34
# File 'lib/ccrypto/ruby/engines/rsa_engine.rb', line 32

def initialize(kp)
  @nativeKeypair = kp
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(mtd, *args, &block) ⇒ Object



103
104
105
106
107
108
109
110
# File 'lib/ccrypto/ruby/engines/rsa_engine.rb', line 103

def method_missing(mtd, *args, &block)
  if @nativeKeypair.respond_to?(mtd)
    teLogger.debug "Sending to nativeKeypair #{mtd}"
    @nativeKeypair.send(mtd,*args, &block)
  else
    super
  end
end

Class Method Details

.from_storage(bin, &block) ⇒ Object

Raises:

  • (KeypairEngineException)


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ccrypto/ruby/engines/rsa_engine.rb', line 76

def self.from_storage(bin, &block)
  raise KeypairEngineException, "Given data to load is empty" if is_empty?(bin)

  case bin
  when String
    teLogger.debug "Given String to load from storage" 
    if is_pem?(bin)
      self.from_pem(bin, &block)
    else
      # binary buffer
      teLogger.debug "Given binary to load from storage" 
      self.from_pkcs12(bin,&block)
    end
  else
    raise KeyBundleStorageException, "Unsupported input type #{bin}"
  end

end

Instance Method Details

#equal?(kp) ⇒ Boolean

Returns:

  • (Boolean)


95
96
97
98
99
100
101
# File 'lib/ccrypto/ruby/engines/rsa_engine.rb', line 95

def equal?(kp)
  if kp.respond_to?(:to_der)
    @nativeKeypair.to_der == kp.to_der
  else
    @nativeKeypair == kp
  end
end

#private_keyObject



43
44
45
46
47
48
# File 'lib/ccrypto/ruby/engines/rsa_engine.rb', line 43

def private_key
  if @privKey.nil?
    @privKey = Ccrypto::RSAPrivateKey.new(@nativeKeypair)
  end
  @privKey
end

#public_keyObject



36
37
38
39
40
41
# File 'lib/ccrypto/ruby/engines/rsa_engine.rb', line 36

def public_key
  if @pubKey.nil?
    @pubKey = RSAPublicKey.new(@nativeKeypair.public_key)
  end
  @pubKey
end

#respond_to_missing?(mtd, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/ccrypto/ruby/engines/rsa_engine.rb', line 112

def respond_to_missing?(mtd, *args, &block)
  @nativeKeypair.respond_to?(mtd)
end

#to_storage(format, &block) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ccrypto/ruby/engines/rsa_engine.rb', line 50

def to_storage(format, &block)
  case format
  when :pkcs12, :p12
    to_pkcs12 do |key|
      case key
      when :keypair
        @nativeKeypair
      else
        block.call(key) if block
      end
    end
  when :pem 
    to_pem do |key|
      case key
      when :keypair
        @nativeKeypair
      else
        block.call(key) if block
      end
    end
  else
    raise KeyBundleStorageException, "Unknown storage format #{format}"
  end
 
end