Sha256: e7a2da87cf68569c2427d81c503a5e080b99c63db0c579241980639e1e5ea9f5

Contents?: true

Size: 1.4 KB

Versions: 29

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

module Ed25519
  # Public key for verifying digital signatures
  class VerifyKey
    # Create a Ed25519::VerifyKey from its serialized Twisted Edwards representation
    #
    # @param key [String] 32-byte string representing a serialized public key
    def initialize(key)
      Ed25519.validate_key_bytes(key)
      @key_bytes = key
    end

    # Verify an Ed25519 signature against the message
    #
    # @param signature [String] 64-byte string containing an Ed25519 signature
    # @param message [String] string containing message to be verified
    #
    # @raise Ed25519::VerifyError signature verification failed
    #
    # @return [true] message verified successfully
    def verify(signature, message)
      if signature.length != SIGNATURE_SIZE
        raise ArgumentError, "expected #{SIGNATURE_SIZE} byte signature, got #{signature.length}"
      end

      return true if Ed25519.provider.verify(@key_bytes, signature, message)
      raise VerifyError, "signature verification failed!"
    end

    # Return a compressed twisted Edwards coordinate representing the public key
    #
    # @return [String] bytestring serialization of this public key
    def to_bytes
      @key_bytes
    end
    alias to_str to_bytes

    # Show hex representation of serialized coordinate in string inspection
    def inspect
      "#<#{self.class}:#{@key_bytes.unpack('H*').first}>"
    end
  end
end

Version data entries

29 entries across 25 versions & 2 rubygems

Version Path
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/ed25519-1.2.4/lib/ed25519/verify_key.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/ed25519-1.2.4/lib/ed25519/verify_key.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/ed25519-1.2.4/lib/ed25519/verify_key.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/ed25519-1.2.4/lib/ed25519/verify_key.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/ed25519-1.2.4/lib/ed25519/verify_key.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/ed25519-1.2.4/lib/ed25519/verify_key.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/ed25519-1.2.4/lib/ed25519/verify_key.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/ed25519-1.2.4/lib/ed25519/verify_key.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/ed25519-1.2.4/lib/ed25519/verify_key.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/ed25519-1.2.4/lib/ed25519/verify_key.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/ed25519-1.2.4/lib/ed25519/verify_key.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/ed25519-1.2.4/lib/ed25519/verify_key.rb
vagrant-unbundled-2.2.6.0 vendor/bundle/ruby/2.6.0/gems/ed25519-1.2.4/lib/ed25519/verify_key.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.6.0/gems/ed25519-1.2.4/lib/ed25519/verify_key.rb
vagrant-unbundled-2.2.5.0 vendor/bundle/ruby/2.5.0/gems/ed25519-1.2.4/lib/ed25519/verify_key.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.6.0/gems/ed25519-1.2.4/lib/ed25519/verify_key.rb
vagrant-unbundled-2.2.4.0 vendor/bundle/ruby/2.5.0/gems/ed25519-1.2.4/lib/ed25519/verify_key.rb
vagrant-unbundled-2.2.3.0 vendor/bundle/ruby/2.5.0/gems/ed25519-1.2.4/lib/ed25519/verify_key.rb
vagrant-unbundled-2.2.2.0 vendor/bundle/ruby/2.5.0/gems/ed25519-1.2.4/lib/ed25519/verify_key.rb
ed25519-1.2.4-java lib/ed25519/verify_key.rb