Class: Ccrypto::Ruby::ED25519Engine

Inherits:
Object
  • Object
show all
Includes:
TeLogger::TeLogHelper
Defined in:
lib/ccrypto/ruby/engines/ed25519_engine.rb

Overview

ED25519KeyBundle

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ ED25519Engine

Returns a new instance of ED25519Engine.



42
43
44
45
# File 'lib/ccrypto/ruby/engines/ed25519_engine.rb', line 42

def initialize(*args, &block)
  @config = args.first 
  teLogger.debug "Config : #{@config}"
end

Class Method Details

.verify(pubKey, val, sign) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ccrypto/ruby/engines/ed25519_engine.rb', line 66

def self.verify(pubKey, val, sign)
  case pubKey
  when Ccrypto::ED25519PublicKey
    uPubKey = pubKey
  else
    raise KeypairEngineException, "Unsupported public key '#{pubKey.class}' for ED25519 operation"
  end

  begin
    uPubKey.verify(sign, val)
  rescue Ed25519::VerifyError => ex
    false
  end
end

Instance Method Details

#generate_keypair(&block) ⇒ Object



47
48
49
50
# File 'lib/ccrypto/ruby/engines/ed25519_engine.rb', line 47

def generate_keypair(&block)
  teLogger.debug "Generating ED25519 keypair"
  ED25519KeyBundle.new(Ed25519::SigningKey.generate)
end

#sign(val) ⇒ Object

Raises:

  • (KeypairEngineException)


52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ccrypto/ruby/engines/ed25519_engine.rb', line 52

def sign(val)
   
  raise KeypairEngineException, "Keypair is required" if @config.keypair.nil?
  raise KeypairEngineException, "ED25519 keypair is required" if not @config.keypair.is_a?(ED25519KeyBundle)

  kp = @config.keypair

  res = kp.nativeKeypair.sign(val)
  teLogger.debug "Data of length #{val.length} signed using ED25519"

  res

end