Class: Ripple::Encryption::BinarySerializer
- Inherits:
-
Object
- Object
- Ripple::Encryption::BinarySerializer
- Defined in:
- lib/ripple-encryption/types/binary_serializer.rb
Overview
Implements the Riak::Serializer API for the purpose of encrypting/decrypting Ripple documents as raw binary.
Example usage:
path = File.join(ROOT_DIR,'config','encryption.yml')
::Riak::Serializers['application/x-binary-encrypted'] = Ripple::Encryption::BinarySerializer.new
(
OpenSSL::Cipher.new(config['cipher']), path
)
class MyDocument
include Ripple::Document
include Ripple::Encryption
end
Constant Summary collapse
- REGISTER_KEY =
'application/x-binary-encrypted'
Instance Attribute Summary collapse
-
#cipher ⇒ OpenSSL::Cipher, OpenSSL::PKey::*
The cipher used to encrypt the object.
-
#iv ⇒ Object
Cipher-specific settings.
-
#key ⇒ Object
Cipher-specific settings.
-
#key_length ⇒ Object
Cipher-specific settings.
-
#padding ⇒ Object
Cipher-specific settings.
Instance Method Summary collapse
-
#dump(object) ⇒ String
Serializes and encrypts the Ruby object using the assigned cipher and Content-Type.
-
#initialize(cipher, path) ⇒ BinarySerializer
constructor
Creates a serializer using the provided cipher and internal content type.
-
#load(object) ⇒ Object
Decrypts and deserializes the blob using the assigned cipher and Content-Type.
Constructor Details
#initialize(cipher, path) ⇒ BinarySerializer
Creates a serializer using the provided cipher and internal content type. Be sure to set the #key, #iv, #key_length, #padding as appropriate for the cipher before attempting (de-)serialization.
38 39 40 41 |
# File 'lib/ripple-encryption/types/binary_serializer.rb', line 38 def initialize(cipher, path) @cipher, @content_type = cipher, REGISTER_KEY @config = Ripple::Encryption::Config.new(path) end |
Instance Attribute Details
#cipher ⇒ OpenSSL::Cipher, OpenSSL::PKey::*
Returns the cipher used to encrypt the object.
24 25 26 |
# File 'lib/ripple-encryption/types/binary_serializer.rb', line 24 def cipher @cipher end |
#iv ⇒ Object
Cipher-specific settings
28 29 30 |
# File 'lib/ripple-encryption/types/binary_serializer.rb', line 28 def iv @iv end |
#key ⇒ Object
Cipher-specific settings
28 29 30 |
# File 'lib/ripple-encryption/types/binary_serializer.rb', line 28 def key @key end |
#key_length ⇒ Object
Cipher-specific settings
28 29 30 |
# File 'lib/ripple-encryption/types/binary_serializer.rb', line 28 def key_length @key_length end |
#padding ⇒ Object
Cipher-specific settings
28 29 30 |
# File 'lib/ripple-encryption/types/binary_serializer.rb', line 28 def padding @padding end |
Instance Method Details
#dump(object) ⇒ String
Serializes and encrypts the Ruby object using the assigned cipher and Content-Type.
47 48 49 |
# File 'lib/ripple-encryption/types/binary_serializer.rb', line 47 def dump(object) BinaryDocument.new(@config, object).encrypt end |
#load(object) ⇒ Object
Decrypts and deserializes the blob using the assigned cipher and Content-Type.
55 56 57 58 |
# File 'lib/ripple-encryption/types/binary_serializer.rb', line 55 def load(object) # this serializer now only supports the v2 (0.0.2 - 0.0.4) format return EncryptedBinaryDocument.new(@config, object).decrypt end |