Sha256: d49990d6643ee79f6ffc436ff5ab0c7c63e188a46424258027c113bbddeaea41

Contents?: true

Size: 1.62 KB

Versions: 11

Compression:

Stored size: 1.62 KB

Contents

# encoding: binary
# frozen_string_literal: true

module RbNaCl
  module Boxes
    class Curve25519XSalsa20Poly1305
      # RbNaCl::Box public key. Send it (securely!) to your friends.
      #
      # This class stores the NaCL public key, and provides some convenience
      # functions for working with it.
      class PublicKey
        include KeyComparator
        include Serializable

        # The size of the key, in bytes
        BYTES = Boxes::Curve25519XSalsa20Poly1305::PUBLICKEYBYTES

        # Initializes a new PublicKey for key operations.
        #
        # Takes the (optionally encoded) public key bytes.  This can be shared with
        # many people and used to establish key pairs with their private key, for
        # the exchanging of messages using a RbNaCl::Box
        #
        # @param public_key [String] The public key
        #
        # @raise [RbNaCl::LengthError] If the key is not valid after decoding.
        #
        # @return A new PublicKey
        def initialize(public_key)
          @public_key = Util.check_string(public_key, BYTES, "Public key")
        end

        # The raw bytes of the key
        #
        # @return [String] the raw bytes.
        def to_bytes
          @public_key
        end

        # The crypto primitive the PublicKey class is to be used for
        #
        # @return [Symbol] The primitive
        def self.primitive
          :curve25519xsalsa20poly1305
        end

        # The crypto primitive this PublicKey is to be used for.
        #
        # @return [Symbol] The primitive
        def primitive
          self.class.primitive
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
rbnacl-7.1.2 lib/rbnacl/boxes/curve25519xsalsa20poly1305/public_key.rb
rbnacl-7.1.1 lib/rbnacl/boxes/curve25519xsalsa20poly1305/public_key.rb
rbnacl-7.1.0 lib/rbnacl/boxes/curve25519xsalsa20poly1305/public_key.rb
rbnacl-7.0.0 lib/rbnacl/boxes/curve25519xsalsa20poly1305/public_key.rb
rbnacl-6.0.1 lib/rbnacl/boxes/curve25519xsalsa20poly1305/public_key.rb
rbnacl-6.0.0 lib/rbnacl/boxes/curve25519xsalsa20poly1305/public_key.rb
rbnacl-5.0.0 lib/rbnacl/boxes/curve25519xsalsa20poly1305/public_key.rb
rbnacl-4.0.2 lib/rbnacl/boxes/curve25519xsalsa20poly1305/public_key.rb
rbnacl-4.0.1 lib/rbnacl/boxes/curve25519xsalsa20poly1305/public_key.rb
rbnacl-4.0.0 lib/rbnacl/boxes/curve25519xsalsa20poly1305/public_key.rb
rbnacl-4.0.0.pre lib/rbnacl/boxes/curve25519xsalsa20poly1305/public_key.rb