Class: ORE::AES128
- Inherits:
-
Object
- Object
- ORE::AES128
- Defined in:
- lib/ore/aes128.rb,
lib/ore/aes128/ciphertext.rb
Defined Under Namespace
Classes: Ciphertext
Class Method Summary collapse
-
.new(k1, k2, b, n) ⇒ Object
Create a new ORE::AES128 “cipher” – an object capable of encrypting plaintexts into ORE ciphertexts.
Instance Method Summary collapse
-
#encrypt(plaintext) ⇒ Object
Encrypt a plaintext into an ORE::AES128::Ciphertext.
Class Method Details
.new(k1, k2, b, n) ⇒ Object
Create a new ORE::AES128 “cipher” – an object capable of encrypting plaintexts into ORE ciphertexts.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ore/aes128.rb', line 28 def self.new(k1, k2, b, n) validate_key(k1, "k1") validate_key(k2, "k2") unless b == 64 raise ArgumentError, "Only 64 bit ORE plaintexts are supported at present" end unless n == 8 raise ArgumentError, "Only 8 bit ORE blocks are supported at present" end _new(k1, k2, b, n) end |
Instance Method Details
#encrypt(plaintext) ⇒ Object
the type of the object you pass in as the plaintext is crucially important. Different types of object are encoded incompatibly, and comparisons between ciphertexts generated from objects of different types is not guaranteed. For example, ‘#encrypt(-3.0) < #encrypt(1)` will not necessarily be true, even though `#encrypt(-3.0) < #encrypt(1.0)` is guaranteed.
Encrypt a plaintext into an ORE::AES128::Ciphertext.
The currently supported types are:
-
‘Integer` – must be in the range 0..2**64-1 (inclusive). Will be encoded as an ORE `uint64`.
-
‘Float` – can be any double precision floating-point number, except for a NaN.
-
‘String` – any valid UTF-8 string. Will be hashed into a 64-bit value for storage.
-
‘Range` – a range of Integers, Floats, Dates, or Times; both ends must be of the
same type. Indefinite beginnings *or* ends are supported, but not both.
-
‘Date`, `Time` – will be converted into milliseconds relative to the UTC epoch.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ore/aes128.rb', line 74 def encrypt(plaintext) case plaintext when Integer encrypt_u64(plaintext) when Float encrypt_f64(plaintext) when String encrypt_string(plaintext) when TrueClass, FalseClass encrypt_bool(plaintext) when Range encrypt_range(plaintext) when Date encrypt(plaintext.to_time) when Time encrypt_time(plaintext) else raise ArgumentError, "Do not know how to ORE encrypt a #{plaintext.class}" end end |