enquo-core 0.7.0.2.gb37f667-arm64-darwin → 0.7.0.5.gb281772-arm64-darwin
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ext/enquo/Cargo.lock +59 -133
- data/ext/enquo/Cargo.toml +2 -2
- data/ext/enquo/src/field.rs +342 -0
- data/ext/enquo/src/lib.rs +29 -309
- data/ext/enquo/src/root.rs +39 -0
- data/ext/enquo/src/root_key.rs +67 -0
- data/lib/2.7/enquo.bundle +0 -0
- data/lib/3.0/enquo.bundle +0 -0
- data/lib/3.1/enquo.bundle +0 -0
- data/lib/3.2/enquo.bundle +0 -0
- data/lib/enquo.rb +2 -4
- metadata +5 -6
- data/lib/enquo/field.rb +0 -173
- data/lib/enquo/root.rb +0 -28
- data/lib/enquo/root_key/static.rb +0 -27
- data/lib/enquo/root_key.rb +0 -1
data/ext/enquo/src/lib.rs
CHANGED
@@ -1,320 +1,40 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
mod field;
|
2
|
+
mod root;
|
3
|
+
mod root_key;
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
VerifiedObject, VM,
|
8
|
-
};
|
5
|
+
#[magnus::init]
|
6
|
+
fn init() -> Result<(), magnus::Error> {
|
7
|
+
let base_mod = magnus::define_module("Enquo")?;
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
root::init(&base_mod)?;
|
10
|
+
root_key::init(&base_mod)?;
|
11
|
+
field::init(&base_mod)?;
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
key_provider::Static,
|
17
|
-
StaticRootKeyWrapper,
|
18
|
-
STATIC_ROOT_KEY_WRAPPER
|
19
|
-
);
|
20
|
-
wrappable_struct!(Field, FieldWrapper, FIELD_WRAPPER);
|
13
|
+
Ok(())
|
14
|
+
}
|
21
15
|
|
22
|
-
fn
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
16
|
+
fn enquo_exception() -> Result<magnus::ExceptionClass, magnus::Error> {
|
17
|
+
magnus::ExceptionClass::from_value(magnus::eval("::Enquo::Error")?).ok_or_else(|| {
|
18
|
+
magnus::Error::new(
|
19
|
+
magnus::exception::runtime_error(),
|
20
|
+
"failed to get RClass from Enquo::Error value".to_string(),
|
27
21
|
)
|
28
22
|
})
|
29
|
-
.unwrap()
|
30
|
-
}
|
31
|
-
|
32
|
-
unsafe_methods!(
|
33
|
-
EnquoRoot,
|
34
|
-
_rbself,
|
35
|
-
fn enquo_root_new_from_static_root_key(root_key_obj: EnquoRootKeyStatic) -> EnquoRoot {
|
36
|
-
let rk = root_key_obj.get_data(&*STATIC_ROOT_KEY_WRAPPER);
|
37
|
-
let root = maybe_raise(Root::new(rk), "Failed to create Enquo::Root");
|
38
|
-
|
39
|
-
let klass = Module::from_existing("Enquo").get_nested_class("Root");
|
40
|
-
klass.wrap_data(root, &*ROOT_WRAPPER)
|
41
|
-
},
|
42
|
-
fn enquo_root_field(relation_obj: RString, name_obj: RString) -> EnquoField {
|
43
|
-
let relation = relation_obj.to_vec_u8_unchecked();
|
44
|
-
let name = name_obj.to_vec_u8_unchecked();
|
45
|
-
|
46
|
-
let root = _rbself.get_data(&*ROOT_WRAPPER);
|
47
|
-
|
48
|
-
let field = maybe_raise(
|
49
|
-
root.field(&relation, &name),
|
50
|
-
"Failed to create Enquo::Field",
|
51
|
-
);
|
52
|
-
|
53
|
-
let klass = Module::from_existing("Enquo").get_nested_class("Field");
|
54
|
-
klass.wrap_data(field, &*FIELD_WRAPPER)
|
55
|
-
}
|
56
|
-
);
|
57
|
-
|
58
|
-
unsafe_methods!(
|
59
|
-
EnquoRootKeyStatic,
|
60
|
-
_rbself,
|
61
|
-
fn enquo_root_key_static_new(root_key_obj: RString) -> EnquoRootKeyStatic {
|
62
|
-
let root_key = root_key_obj.to_vec_u8_unchecked();
|
63
|
-
|
64
|
-
let k = key_provider::Static::new(&root_key);
|
65
|
-
let klass = Module::from_existing("Enquo")
|
66
|
-
.get_nested_class("RootKey")
|
67
|
-
.get_nested_class("Static");
|
68
|
-
klass.wrap_data(k, &*STATIC_ROOT_KEY_WRAPPER)
|
69
|
-
},
|
70
|
-
);
|
71
|
-
|
72
|
-
impl VerifiedObject for EnquoRootKeyStatic {
|
73
|
-
fn is_correct_type<T: Object>(object: &T) -> bool {
|
74
|
-
let klass = Module::from_existing("Enquo")
|
75
|
-
.get_nested_class("RootKey")
|
76
|
-
.get_nested_class("Static");
|
77
|
-
klass.case_equals(object)
|
78
|
-
}
|
79
|
-
|
80
|
-
fn error_message() -> &'static str {
|
81
|
-
"Provided object is not an Enquo::RootKey::Static instance"
|
82
|
-
}
|
83
23
|
}
|
84
24
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
fn enquo_field_encrypt_boolean(b_obj: RBoolean, context_obj: RString, mode_obj: Symbol) -> RString {
|
91
|
-
let b = b_obj.to_bool();
|
92
|
-
let context = context_obj.to_vec_u8_unchecked();
|
93
|
-
let mode = mode_obj.to_str();
|
94
|
-
|
95
|
-
let field = rbself.get_data(&*FIELD_WRAPPER);
|
96
|
-
|
97
|
-
let mut res = maybe_raise(
|
98
|
-
if mode == "unsafe" {
|
99
|
-
Boolean::new_with_unsafe_parts(b, &context, field)
|
100
|
-
} else {
|
101
|
-
Boolean::new(b, &context, field)
|
102
|
-
},
|
103
|
-
"Failed to create encrypted boolean",
|
104
|
-
);
|
105
|
-
if mode == "no_query" {
|
106
|
-
res.make_unqueryable();
|
107
|
-
}
|
108
|
-
|
109
|
-
RString::new_utf8(&maybe_raise(serde_json::to_string(&res), "Failed to JSONify ciphertext"))
|
110
|
-
},
|
111
|
-
fn enquo_field_decrypt_boolean(ciphertext_obj: RString, context_obj: RString) -> RBoolean {
|
112
|
-
let ct = ciphertext_obj.to_str_unchecked();
|
113
|
-
let context = context_obj.to_vec_u8_unchecked();
|
114
|
-
|
115
|
-
let field = rbself.get_data(&*FIELD_WRAPPER);
|
116
|
-
|
117
|
-
let e_value: Boolean =
|
118
|
-
maybe_raise(serde_json::from_str(ct), "Failed to deserialize ciphertext");
|
119
|
-
|
120
|
-
let value = maybe_raise(
|
121
|
-
e_value.decrypt(&context, field),
|
122
|
-
"Failed to decrypt boolean value",
|
123
|
-
);
|
124
|
-
RBoolean::new(value)
|
125
|
-
},
|
126
|
-
fn enquo_field_encrypt_i64(i_obj: Integer, context_obj: RString, mode_obj: Symbol) -> RString {
|
127
|
-
let i = i_obj.to_i64();
|
128
|
-
let context = context_obj.to_vec_u8_unchecked();
|
129
|
-
let mode = mode_obj.to_str();
|
130
|
-
|
131
|
-
let field = rbself.get_data(&*FIELD_WRAPPER);
|
132
|
-
|
133
|
-
let mut res = maybe_raise(
|
134
|
-
if mode == "unsafe" {
|
135
|
-
I64::new_with_unsafe_parts(i, &context, field)
|
136
|
-
} else {
|
137
|
-
I64::new(i, &context, field)
|
138
|
-
},
|
139
|
-
"Failed to create encrypted i64",
|
140
|
-
);
|
141
|
-
if mode == "no_query" {
|
142
|
-
res.make_unqueryable();
|
143
|
-
}
|
144
|
-
|
145
|
-
RString::new_utf8(&maybe_raise(serde_json::to_string(&res), "Failed to JSONify ciphertext"))
|
146
|
-
},
|
147
|
-
fn enquo_field_decrypt_i64(ciphertext_obj: RString, context_obj: RString) -> Integer {
|
148
|
-
let ct = ciphertext_obj.to_str_unchecked();
|
149
|
-
let context = context_obj.to_vec_u8_unchecked();
|
25
|
+
fn maybe_raise<T, E: std::error::Error>(
|
26
|
+
r: Result<T, E>,
|
27
|
+
s: Option<&str>,
|
28
|
+
) -> Result<T, magnus::Error> {
|
29
|
+
let ex_class = enquo_exception()?;
|
150
30
|
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
let value = maybe_raise(
|
158
|
-
e_value.decrypt(&context, field),
|
159
|
-
"Failed to decrypt i64 value",
|
160
|
-
);
|
161
|
-
Integer::from(value)
|
162
|
-
},
|
163
|
-
fn enquo_field_encrypt_date(
|
164
|
-
y_obj: Integer,
|
165
|
-
m_obj: Integer,
|
166
|
-
d_obj: Integer,
|
167
|
-
context_obj: RString,
|
168
|
-
mode_obj: Symbol
|
169
|
-
) -> RString {
|
170
|
-
let y = y_obj.to_i32() as i16;
|
171
|
-
let m = m_obj.to_i32() as u8;
|
172
|
-
let d = d_obj.to_i32() as u8;
|
173
|
-
let context = context_obj.to_vec_u8_unchecked();
|
174
|
-
let mode = mode_obj.to_str();
|
175
|
-
|
176
|
-
let field = rbself.get_data(&*FIELD_WRAPPER);
|
177
|
-
|
178
|
-
let mut res = maybe_raise(
|
179
|
-
if mode == "unsafe" {
|
180
|
-
Date::new_with_unsafe_parts(
|
181
|
-
(y, m, d),
|
182
|
-
&context,
|
183
|
-
field,
|
184
|
-
)
|
185
|
-
} else {
|
186
|
-
Date::new((y, m, d), &context, field)
|
187
|
-
},
|
188
|
-
"Failed to create encrypted date",
|
189
|
-
);
|
190
|
-
if mode == "no_query" {
|
191
|
-
res.make_unqueryable();
|
192
|
-
}
|
193
|
-
|
194
|
-
RString::new_utf8(&maybe_raise(serde_json::to_string(&res), "Failed to JSONify ciphertext"))
|
195
|
-
},
|
196
|
-
fn enquo_field_decrypt_date(ciphertext_obj: RString, context_obj: RString) -> AnyObject {
|
197
|
-
let ct = ciphertext_obj.to_str_unchecked();
|
198
|
-
let context = context_obj.to_vec_u8_unchecked();
|
199
|
-
|
200
|
-
let field = rbself.get_data(&*FIELD_WRAPPER);
|
201
|
-
|
202
|
-
let e_value: Date =
|
203
|
-
maybe_raise(serde_json::from_str(ct), "Failed to deserialize ciphertext");
|
204
|
-
|
205
|
-
let (y, m, d) = maybe_raise(
|
206
|
-
e_value.decrypt(&context, field),
|
207
|
-
"Failed to decrypt date value",
|
208
|
-
);
|
209
|
-
let klass = Class::from_existing("Date");
|
210
|
-
let args: [AnyObject; 3] = [
|
211
|
-
Integer::from(y as i32).into(),
|
212
|
-
Integer::from(m as i32).into(),
|
213
|
-
Integer::from(d as i32).into(),
|
214
|
-
];
|
215
|
-
klass.protect_send("new", &args).unwrap()
|
216
|
-
}
|
217
|
-
fn enquo_field_encrypt_text(
|
218
|
-
text_obj: RString,
|
219
|
-
context_obj: RString,
|
220
|
-
mode_obj: Symbol,
|
221
|
-
order_code_len_obj: Integer
|
222
|
-
) -> RString {
|
223
|
-
let text = text_obj.to_str();
|
224
|
-
let context = context_obj.to_vec_u8_unchecked();
|
225
|
-
let mode = mode_obj.to_str();
|
226
|
-
|
227
|
-
let field = rbself.get_data(&*FIELD_WRAPPER);
|
228
|
-
|
229
|
-
let mut res = maybe_raise(
|
230
|
-
if mode == "unsafe" {
|
231
|
-
Text::new_with_unsafe_parts(
|
232
|
-
text,
|
233
|
-
&context,
|
234
|
-
field,
|
235
|
-
None,
|
236
|
-
)
|
237
|
-
} else if mode == "orderable" {
|
238
|
-
let order_code_len = order_code_len_obj.to_i64() as u8;
|
239
|
-
Text::new_with_unsafe_parts(
|
240
|
-
text,
|
241
|
-
&context,
|
242
|
-
field,
|
243
|
-
Some(order_code_len),
|
244
|
-
)
|
245
|
-
} else {
|
246
|
-
Text::new(text, &context, field)
|
31
|
+
r.map_err(|e| {
|
32
|
+
magnus::Error::new(
|
33
|
+
ex_class,
|
34
|
+
match &s {
|
35
|
+
None => e.to_string(),
|
36
|
+
Some(s) => format!("{s}: {e}"),
|
247
37
|
},
|
248
|
-
|
249
|
-
|
250
|
-
if mode == "no_query" {
|
251
|
-
maybe_raise(res.make_unqueryable(), "Failed to make ciphertext unqueryable");
|
252
|
-
}
|
253
|
-
|
254
|
-
RString::new_utf8(&maybe_raise(serde_json::to_string(&res), "Failed to JSONify ciphertext"))
|
255
|
-
},
|
256
|
-
fn enquo_field_decrypt_text(ciphertext_obj: RString, context_obj: RString) -> RString {
|
257
|
-
let ct = ciphertext_obj.to_str_unchecked();
|
258
|
-
let context = context_obj.to_vec_u8_unchecked();
|
259
|
-
|
260
|
-
let field = rbself.get_data(&*FIELD_WRAPPER);
|
261
|
-
|
262
|
-
let e_value: Text =
|
263
|
-
maybe_raise(serde_json::from_str(ct), "Failed to deserialize ciphertext");
|
264
|
-
|
265
|
-
let s = maybe_raise(e_value.decrypt(&context, field), "Failed to decrypt text value");
|
266
|
-
|
267
|
-
RString::new_utf8(&s)
|
268
|
-
},
|
269
|
-
fn enquo_field_encrypt_text_length_query(
|
270
|
-
len_obj: Integer
|
271
|
-
) -> RString {
|
272
|
-
let len = len_obj.to_u32();
|
273
|
-
|
274
|
-
let field = rbself.get_data(&*FIELD_WRAPPER);
|
275
|
-
|
276
|
-
let v_set = maybe_raise(Text::query_length(len, field), "Failed to encrypt length as value set");
|
277
|
-
RString::new_utf8(&maybe_raise(serde_json::to_string(&v_set), "Failed to JSONify value set"))
|
278
|
-
}
|
279
|
-
);
|
280
|
-
|
281
|
-
#[allow(non_snake_case)]
|
282
|
-
#[no_mangle]
|
283
|
-
pub extern "C" fn Init_enquo() {
|
284
|
-
Module::from_existing("Enquo").define(|topmod| {
|
285
|
-
topmod
|
286
|
-
.define_nested_class("Root", None)
|
287
|
-
.define(|rootklass| {
|
288
|
-
rootklass.singleton_class().def_private(
|
289
|
-
"_new_from_static_root_key",
|
290
|
-
enquo_root_new_from_static_root_key,
|
291
|
-
);
|
292
|
-
rootklass.def_private("_field", enquo_root_field);
|
293
|
-
});
|
294
|
-
topmod
|
295
|
-
.define_nested_class("Field", None)
|
296
|
-
.define(|fieldklass| {
|
297
|
-
fieldklass.def_private("_encrypt_boolean", enquo_field_encrypt_boolean);
|
298
|
-
fieldklass.def_private("_decrypt_boolean", enquo_field_decrypt_boolean);
|
299
|
-
fieldklass.def_private("_encrypt_i64", enquo_field_encrypt_i64);
|
300
|
-
fieldklass.def_private("_decrypt_i64", enquo_field_decrypt_i64);
|
301
|
-
fieldklass.def_private("_encrypt_date", enquo_field_encrypt_date);
|
302
|
-
fieldklass.def_private("_decrypt_date", enquo_field_decrypt_date);
|
303
|
-
fieldklass.def_private("_encrypt_text", enquo_field_encrypt_text);
|
304
|
-
fieldklass.def_private("_decrypt_text", enquo_field_decrypt_text);
|
305
|
-
fieldklass.def_private(
|
306
|
-
"_encrypt_text_length_query",
|
307
|
-
enquo_field_encrypt_text_length_query,
|
308
|
-
);
|
309
|
-
});
|
310
|
-
topmod.define_nested_module("RootKey").define(|rkmod| {
|
311
|
-
rkmod
|
312
|
-
.define_nested_class("Static", None)
|
313
|
-
.define(|statickeyklass| {
|
314
|
-
statickeyklass
|
315
|
-
.singleton_class()
|
316
|
-
.def_private("_new", enquo_root_key_static_new);
|
317
|
-
});
|
318
|
-
});
|
319
|
-
});
|
38
|
+
)
|
39
|
+
})
|
320
40
|
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
use magnus::{class, function, method, prelude::*, RModule};
|
2
|
+
use std::ops::Deref;
|
3
|
+
|
4
|
+
use crate::{field::Field, maybe_raise, root_key::RootKey};
|
5
|
+
|
6
|
+
#[magnus::wrap(class = "Enquo::Root")]
|
7
|
+
struct Root(enquo_core::Root);
|
8
|
+
|
9
|
+
impl Deref for Root {
|
10
|
+
type Target = enquo_core::Root;
|
11
|
+
|
12
|
+
fn deref(&self) -> &Self::Target {
|
13
|
+
&self.0
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
impl Root {
|
18
|
+
fn new(k: &RootKey) -> Result<Self, magnus::Error> {
|
19
|
+
Ok(Self(maybe_raise(
|
20
|
+
enquo_core::Root::new(k.deref().clone()),
|
21
|
+
None,
|
22
|
+
)?))
|
23
|
+
}
|
24
|
+
|
25
|
+
fn field(&self, relation: String, name: String) -> Result<Field, magnus::Error> {
|
26
|
+
Ok(Field(maybe_raise(
|
27
|
+
self.0.field(relation.as_bytes(), name.as_bytes()),
|
28
|
+
None,
|
29
|
+
)?))
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
pub fn init(base: &RModule) -> Result<(), magnus::Error> {
|
34
|
+
let class = base.define_class("Root", class::object())?;
|
35
|
+
|
36
|
+
class.define_singleton_method("new", function!(Root::new, 1))?;
|
37
|
+
class.define_method("field", method!(Root::field, 2))?;
|
38
|
+
Ok(())
|
39
|
+
}
|
@@ -0,0 +1,67 @@
|
|
1
|
+
use enquo_core::{key_provider, key_provider::KeyProvider};
|
2
|
+
use magnus::{class, encoding, exception, function, prelude::*, RModule};
|
3
|
+
use std::ops::Deref;
|
4
|
+
use std::sync::Arc;
|
5
|
+
|
6
|
+
#[magnus::wrap(class = "Enquo::RootKey")]
|
7
|
+
pub struct RootKey(Arc<dyn KeyProvider>);
|
8
|
+
|
9
|
+
impl Deref for RootKey {
|
10
|
+
type Target = Arc<dyn KeyProvider>;
|
11
|
+
|
12
|
+
fn deref(&self) -> &Self::Target {
|
13
|
+
&self.0
|
14
|
+
}
|
15
|
+
}
|
16
|
+
|
17
|
+
fn new_static_root_key(k_str: magnus::RString) -> Result<RootKey, magnus::Error> {
|
18
|
+
let encindex = k_str.enc_get();
|
19
|
+
|
20
|
+
let k: &[u8] = &if encindex == encoding::Index::ascii8bit() {
|
21
|
+
if k_str.len() == 32 {
|
22
|
+
Ok(unsafe { (*k_str.as_slice()).to_vec() })
|
23
|
+
} else {
|
24
|
+
Err(magnus::Error::new(
|
25
|
+
exception::arg_error(),
|
26
|
+
"binary key string must be exactly 32 bytes long".to_string(),
|
27
|
+
))
|
28
|
+
}
|
29
|
+
} else if encindex == encoding::Index::utf8() || encindex == encoding::Index::usascii() {
|
30
|
+
if k_str.len() == 64 {
|
31
|
+
Ok(unsafe {
|
32
|
+
hex::decode(k_str.as_slice()).map_err(|e| {
|
33
|
+
magnus::Error::new(
|
34
|
+
exception::arg_error(),
|
35
|
+
format!("hex key must only contain valid hex characters: {e}"),
|
36
|
+
)
|
37
|
+
})?
|
38
|
+
})
|
39
|
+
} else {
|
40
|
+
Err(magnus::Error::new(
|
41
|
+
exception::arg_error(),
|
42
|
+
format!(
|
43
|
+
"hex key string must be exactly 64 characters long (got {} characters)",
|
44
|
+
k_str.len()
|
45
|
+
),
|
46
|
+
))
|
47
|
+
}
|
48
|
+
} else {
|
49
|
+
Err(magnus::Error::new(
|
50
|
+
exception::encoding_error(),
|
51
|
+
"key string must be encoded as BINARY or UTF-8".to_string(),
|
52
|
+
))
|
53
|
+
}?;
|
54
|
+
|
55
|
+
Ok(RootKey(Arc::new(key_provider::Static::new(k))))
|
56
|
+
}
|
57
|
+
|
58
|
+
pub fn init(base: &RModule) -> Result<(), magnus::Error> {
|
59
|
+
let base_class = base.define_class("RootKey", class::object())?;
|
60
|
+
|
61
|
+
{
|
62
|
+
let class = base_class.define_class("Static", base_class)?;
|
63
|
+
class.define_singleton_method("new", function!(new_static_root_key, 1))?;
|
64
|
+
}
|
65
|
+
|
66
|
+
Ok(())
|
67
|
+
}
|
data/lib/2.7/enquo.bundle
CHANGED
Binary file
|
data/lib/3.0/enquo.bundle
CHANGED
Binary file
|
data/lib/3.1/enquo.bundle
CHANGED
Binary file
|
data/lib/3.2/enquo.bundle
CHANGED
Binary file
|
data/lib/enquo.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require "date"
|
2
|
+
|
1
3
|
module Enquo
|
2
4
|
class Error < StandardError; end
|
3
5
|
end
|
@@ -12,7 +14,3 @@ rescue LoadError
|
|
12
14
|
raise LoadError, "Failed to load enquo.#{RbConfig::CONFIG["DLEXT"]}; either it hasn't been built, or was built incorrectly for your system"
|
13
15
|
end
|
14
16
|
end
|
15
|
-
|
16
|
-
require_relative "./enquo/root"
|
17
|
-
require_relative "./enquo/root_key"
|
18
|
-
require_relative "./enquo/field"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enquo-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.0.
|
4
|
+
version: 0.7.0.5.gb281772
|
5
5
|
platform: arm64-darwin
|
6
6
|
authors:
|
7
7
|
- Matt Palmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -170,17 +170,16 @@ files:
|
|
170
170
|
- ext/enquo/Cargo.lock
|
171
171
|
- ext/enquo/Cargo.toml
|
172
172
|
- ext/enquo/extconf.rb
|
173
|
+
- ext/enquo/src/field.rs
|
173
174
|
- ext/enquo/src/lib.rs
|
175
|
+
- ext/enquo/src/root.rs
|
176
|
+
- ext/enquo/src/root_key.rs
|
174
177
|
- lib/2.7/enquo.bundle
|
175
178
|
- lib/3.0/enquo.bundle
|
176
179
|
- lib/3.1/enquo.bundle
|
177
180
|
- lib/3.2/enquo.bundle
|
178
181
|
- lib/enquo-core.rb
|
179
182
|
- lib/enquo.rb
|
180
|
-
- lib/enquo/field.rb
|
181
|
-
- lib/enquo/root.rb
|
182
|
-
- lib/enquo/root_key.rb
|
183
|
-
- lib/enquo/root_key/static.rb
|
184
183
|
- lib/enquo_core.rb
|
185
184
|
homepage: https://enquo.org/active_enquo
|
186
185
|
licenses: []
|
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
|