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