PageRenderTime 35ms CodeModel.GetById 26ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/bundle/jruby/2.1/gems/rbnacl-3.0.1/lib/rbnacl/boxes/curve25519xsalsa20poly1305/public_key.rb

https://github.com/delowong/logstash
Ruby | 53 lines | 19 code | 8 blank | 26 comment | 0 complexity | 59692448012259d6059a628d3986506f MD5 | raw file
 1# encoding: binary
 2
 3module RbNaCl
 4  # RbNaCl::Box public key. Send it (securely!) to your friends.
 5  #
 6  # This class stores the NaCL public key, and provides some convenience
 7  # functions for working with it.
 8  class Boxes::Curve25519XSalsa20Poly1305::PublicKey
 9
10    include KeyComparator
11    include Serializable
12
13    # The size of the key, in bytes
14    BYTES = Boxes::Curve25519XSalsa20Poly1305::PUBLICKEYBYTES
15
16    # Initializes a new PublicKey for key operations.
17    #
18    # Takes the (optionally encoded) public key bytes.  This can be shared with
19    # many people and used to establish key pairs with their private key, for
20    # the exchanging of messages using a RbNaCl::Box
21    #
22    # @param public_key [String] The public key
23    #
24    # @raise [RbNaCl::LengthError] If the key is not valid after decoding.
25    #
26    # @return A new PublicKey
27    def initialize(public_key)
28      @public_key = Util.check_string(public_key, BYTES, "Public key")
29    end
30
31    # The raw bytes of the key
32    #
33    # @return [String] the raw bytes.
34    def to_bytes
35      @public_key
36    end
37
38    # The crypto primitive the PublicKey class is to be used for
39    #
40    # @return [Symbol] The primitive
41    def self.primitive
42      :curve25519xsalsa20poly1305
43    end
44
45    # The crypto primitive this PublicKey is to be used for.
46    #
47    # @return [Symbol] The primitive
48    def primitive
49      self.class.primitive
50    end
51  end
52
53end