enquo-core 0.7.0.2.gb37f667-aarch64-linux → 0.8.0-aarch64-linux

Sign up to get free protection for your applications and to get access to all the features.
data/lib/enquo/field.rb DELETED
@@ -1,173 +0,0 @@
1
- require "date"
2
-
3
- module Enquo
4
- class Field
5
- def self.new(*_)
6
- raise RuntimeError, "Enquo::Field cannot be instantiated directly; use Enquo::Crypto#field instead"
7
- end
8
-
9
- def encrypt_boolean(b, ctx, safety: true, no_query: false)
10
- unless b.is_a?(TrueClass) || b.is_a?(FalseClass)
11
- raise ArgumentError, "Enquo::Field#encrypt_boolean can only encrypt booleans (got an instance of #{b.class})"
12
- end
13
-
14
- unless ctx.is_a?(String)
15
- raise ArgumentError, "Encryption context must be a string (got an instance of #{ctx.class})"
16
- end
17
-
18
- _encrypt_boolean(b, ctx, no_query ? :no_query : safety == :unsafe ? :unsafe : :default)
19
- end
20
-
21
- def decrypt_boolean(data, ctx)
22
- unless data.is_a?(String)
23
- raise ArgumentError, "Enquo::Field#decrypt_boolean can only decrypt from a string (got an instance of #{data.class})"
24
- end
25
-
26
- unless data.encoding == Encoding::UTF_8 && data.valid_encoding?
27
- raise ArgumentError, "Enquo::Field#decrypt_boolean can only decrypt validly-encoded UTF-8 strings (got #{data.encoding})"
28
- end
29
-
30
- unless ctx.is_a?(String)
31
- raise ArgumentError, "Encryption context must be a string (got an instance of #{ctx.class})"
32
- end
33
-
34
- _decrypt_boolean(data, ctx)
35
- end
36
-
37
- def encrypt_i64(i, ctx, safety: true, no_query: false)
38
- unless i.is_a?(Integer)
39
- raise ArgumentError, "Enquo::Field#encrypt_i64 can only encrypt integers (got an instance of #{i.class})"
40
- end
41
-
42
- unless i >= -2 ** 63 && i < 2 ** 63
43
- raise RangeError, "Enquo::Field#encrypt_i64 can only encrypt integers between -2^63 and 2^63-1 (got #{i})"
44
- end
45
-
46
- unless ctx.is_a?(String)
47
- raise ArgumentError, "Encryption context must be a string (got an instance of #{ctx.class})"
48
- end
49
-
50
- _encrypt_i64(i, ctx, no_query ? :no_query : safety == :unsafe ? :unsafe : :default)
51
- end
52
-
53
- def decrypt_i64(data, ctx)
54
- unless data.is_a?(String)
55
- raise ArgumentError, "Enquo::Field#decrypt_i64 can only decrypt from a string (got an instance of #{data.class})"
56
- end
57
-
58
- unless data.encoding == Encoding::UTF_8 && data.valid_encoding?
59
- raise ArgumentError, "Enquo::Field#decrypt_i64 can only decrypt validly-encoded UTF-8 strings (got #{data.encoding})"
60
- end
61
-
62
- unless ctx.is_a?(String)
63
- raise ArgumentError, "Encryption context must be a string (got an instance of #{ctx.class})"
64
- end
65
-
66
- _decrypt_i64(data, ctx)
67
- end
68
-
69
- def encrypt_date(d, ctx, safety: true, no_query: false)
70
- unless d.is_a?(Date)
71
- raise ArgumentError, "Enquo::Field#encrypt_date can only encrypt Dates (got an instance of #{d.class})"
72
- end
73
-
74
- unless d.year >= -2 ** 15 && d.year < 2 ** 15 - 1
75
- raise RangeError, "Enquo::Field#encrypt_date can only encrypt dates where the year is between -32,768 and 32,767 (got #{d.year})"
76
- end
77
-
78
- unless ctx.is_a?(String)
79
- raise ArgumentError, "Encryption context must be a string (got an instance of #{ctx.class})"
80
- end
81
-
82
- _encrypt_date(d.year, d.month, d.day, ctx, no_query ? :no_query : safety == :unsafe ? :unsafe : :default)
83
- end
84
-
85
- def decrypt_date(data, ctx)
86
- unless data.is_a?(String)
87
- raise ArgumentError, "Enquo::Field#decrypt_date can only decrypt from a string (got an instance of #{data.class})"
88
- end
89
-
90
- unless data.encoding == Encoding::UTF_8 && data.valid_encoding?
91
- raise ArgumentError, "Enquo::Field#decrypt_date can only decrypt validly-encoded UTF-8 strings (got #{data.encoding})"
92
- end
93
-
94
- unless ctx.is_a?(String)
95
- raise ArgumentError, "Encryption context must be a string (got an instance of #{ctx.class})"
96
- end
97
-
98
- _decrypt_date(data, ctx)
99
- end
100
-
101
- def encrypt_text(t, ctx, safety: true, no_query: false, order_prefix_length: nil)
102
- unless t.is_a?(String)
103
- raise ArgumentError, "Enquo::Field#encrypt_string can only encrypt Strings (got an instance of #{t.class})"
104
- end
105
-
106
- unless [Encoding::UTF_8, Encoding::US_ASCII].include?(t.encoding)
107
- raise ArgumentError, "Enquo::Field#encrypt_string can only encrypt UTF-8 strings (got a string encoding of #{t.encoding})"
108
- end
109
-
110
- unless t.valid_encoding?
111
- raise ArgumentError, "Enquo::Field#encrypt_string can only encrypt validly-encoded strings"
112
- end
113
-
114
- unless ctx.is_a?(String)
115
- raise ArgumentError, "Encryption context must be a string (got an instance of #{ctx.class})"
116
- end
117
-
118
- unless order_prefix_length.nil?
119
- unless safety == :unsafe
120
- raise ArgumentError, "Ordering is only supported when the text field is marked unsafe"
121
- end
122
-
123
- unless order_prefix_length.is_a?(Integer)
124
- raise ArgumentError, "Ordering prefix length must be an integer (got an instance of #{order_prefix_length.class})"
125
- end
126
-
127
- unless (1..255).include?(order_prefix_length)
128
- raise ArgumentError, "Ordering prefix length must be between 1 and 255 inclusive (got #{order_prefix_length})"
129
- end
130
- end
131
-
132
- mode = if no_query
133
- :no_query
134
- elsif !order_prefix_length.nil?
135
- :orderable
136
- elsif safety == :unsafe
137
- :unsafe
138
- else
139
- :default
140
- end
141
-
142
- _encrypt_text(t, ctx, mode, order_prefix_length)
143
- end
144
-
145
- def decrypt_text(data, ctx)
146
- unless data.is_a?(String)
147
- raise ArgumentError, "Enquo::Field#decrypt_text can only decrypt from a string (got an instance of #{data.class})"
148
- end
149
-
150
- unless data.encoding == Encoding::UTF_8 && data.valid_encoding?
151
- raise ArgumentError, "Enquo::Field#decrypt_date can only decrypt validly-encoded UTF-8 strings (got #{data.encoding})"
152
- end
153
-
154
- unless ctx.is_a?(String)
155
- raise ArgumentError, "Encryption context must be a string (got an instance of #{ctx.class})"
156
- end
157
-
158
- _decrypt_text(data, ctx)
159
- end
160
-
161
- def encrypt_text_length_query(len)
162
- unless len.is_a?(Integer)
163
- raise ArgumentError, "Enquo::Field#encrypt_text_length_query can only encrypt integers (got an instance of #{len.class})"
164
- end
165
-
166
- unless len >= 0 && len < 2 ** 32
167
- raise ArgumentError, "Enquo::Field#encrypt_text_length_query can only encrypt integers between 0 and 2^32-1 (got #{len})"
168
- end
169
-
170
- _encrypt_text_length_query(len)
171
- end
172
- end
173
- end
data/lib/enquo/root.rb DELETED
@@ -1,28 +0,0 @@
1
- module Enquo
2
- class Root
3
- def self.new(key)
4
- case key
5
- when RootKey::Static
6
- _new_from_static_root_key(key)
7
- else
8
- raise ArgumentError, "key must be a root key provider object (got a #{key.class})"
9
- end.tap do |k|
10
- # DIRTY HACK ALERT: take a reference to the key so it doesn't get GC'd
11
- # If someone can come up with a better way to acheive this, I'm all ears
12
- k.instance_variable_set(:@_key, key)
13
- end
14
- end
15
-
16
- def field(relation, name)
17
- if relation.is_a?(Symbol)
18
- relation = relation.to_s
19
- end
20
-
21
- if name.is_a?(Symbol)
22
- name = name.to_s
23
- end
24
-
25
- _field(relation, name)
26
- end
27
- end
28
- end
@@ -1,27 +0,0 @@
1
- module Enquo
2
- module RootKey
3
- class Static
4
- def self.new(k)
5
- unless k.is_a?(String)
6
- raise ArgumentError, "An Enquo static root key must be passed a string"
7
- end
8
-
9
- key = if k.encoding == Encoding::BINARY
10
- unless k.bytesize == 32
11
- raise ArgumentError, "An Enquo static root key must be a 32 byte binary string"
12
- end
13
-
14
- k
15
- else
16
- unless k =~ /\A\h{64}\z/
17
- raise ArgumentError, "An Enquo static root key must be a 64 byte hex string"
18
- end
19
-
20
- [k].pack("H*")
21
- end
22
-
23
- _new(key)
24
- end
25
- end
26
- end
27
- end
@@ -1 +0,0 @@
1
- require_relative "./root_key/static"