enquo-core 0.6.0.7.gc8b36a2 → 0.6.0.11.g8d4f25f
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/enquo-core.gemspec +3 -1
- data/ext/enquo/Cargo.lock +2 -2
- data/ext/enquo/src/lib.rs +43 -2
- data/lib/enquo/field.rb +28 -0
- metadata +19 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94ead69e0c6bf0e50f4c4a78560594d6a5e18e29dffedf9aee04b996b3a9368d
|
4
|
+
data.tar.gz: befbf19e7843e70274f13a1c5a9f86626ba85e10f12a88ce129f86c49efe627e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87c16c88179682cf5510cf6497d861361567144233d00ca1b9823c1629267056537afb48e22ffcaf2f7db814fc3fdf95a6072df9cd2cc4dc93a183c35c4e6f65
|
7
|
+
data.tar.gz: 65405aed7f47b863f2c8ce7f161150978df1aeb9a32918882d46e4282c97b4414c997f2ad7f5124d799a658f11a249e9adde4f31504c24fc299a96fd52f587e9
|
data/enquo-core.gemspec
CHANGED
@@ -24,15 +24,17 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.metadata["bug_tracker_uri"] = "https://github.com/enquo/enquo-core/issues"
|
25
25
|
|
26
26
|
s.files = `git ls-files -z`.split("\0").reject { |f| f =~ /^(G|spec|Rakefile)/ }
|
27
|
+
s.extensions = ["ext/enquo/extconf.rb"]
|
27
28
|
|
28
29
|
s.required_ruby_version = ">= 2.7.0"
|
29
30
|
|
31
|
+
s.add_runtime_dependency 'rb_sys', '~> 0.1'
|
32
|
+
|
30
33
|
s.add_development_dependency 'bundler'
|
31
34
|
s.add_development_dependency 'github-release'
|
32
35
|
s.add_development_dependency 'rake', '~> 13.0'
|
33
36
|
s.add_development_dependency 'rake-compiler', '~> 1.2'
|
34
37
|
s.add_development_dependency 'rake-compiler-dock', '~> 1.2'
|
35
|
-
s.add_development_dependency 'rb_sys', '~> 0.1'
|
36
38
|
s.add_development_dependency 'redcarpet'
|
37
39
|
s.add_development_dependency 'rspec'
|
38
40
|
s.add_development_dependency 'simplecov'
|
data/ext/enquo/Cargo.lock
CHANGED
@@ -211,9 +211,9 @@ dependencies = [
|
|
211
211
|
|
212
212
|
[[package]]
|
213
213
|
name = "cretrit"
|
214
|
-
version = "0.
|
214
|
+
version = "0.4.1"
|
215
215
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
216
|
-
checksum = "
|
216
|
+
checksum = "0b424f56a53c945d026954e4b431c9d8bd3cd8c431574c8f4b77f59e860c366a"
|
217
217
|
dependencies = [
|
218
218
|
"aes",
|
219
219
|
"cmac",
|
data/ext/enquo/src/lib.rs
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
#[macro_use]
|
2
2
|
extern crate rutie;
|
3
3
|
|
4
|
-
use enquo_core::{key_provider, Date, Field, Root, Text, I64};
|
5
|
-
use rutie::{
|
4
|
+
use enquo_core::{key_provider, Boolean, Date, Field, Root, Text, I64};
|
5
|
+
use rutie::{
|
6
|
+
AnyObject, Boolean as RBoolean, Class, Integer, Module, Object, RString, Symbol,
|
7
|
+
VerifiedObject, VM,
|
8
|
+
};
|
6
9
|
|
7
10
|
class!(EnquoRoot);
|
8
11
|
class!(EnquoRootKeyStatic);
|
@@ -84,6 +87,42 @@ impl VerifiedObject for EnquoRootKeyStatic {
|
|
84
87
|
unsafe_methods!(
|
85
88
|
EnquoField,
|
86
89
|
rbself,
|
90
|
+
fn enquo_field_encrypt_bool(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 bool",
|
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_bool(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 bool value",
|
123
|
+
);
|
124
|
+
RBoolean::new(value)
|
125
|
+
},
|
87
126
|
fn enquo_field_encrypt_i64(i_obj: Integer, context_obj: RString, mode_obj: Symbol) -> RString {
|
88
127
|
let i = i_obj.to_i64();
|
89
128
|
let context = context_obj.to_vec_u8_unchecked();
|
@@ -235,6 +274,8 @@ pub extern "C" fn Init_enquo() {
|
|
235
274
|
topmod
|
236
275
|
.define_nested_class("Field", None)
|
237
276
|
.define(|fieldklass| {
|
277
|
+
fieldklass.def_private("_encrypt_bool", enquo_field_encrypt_bool);
|
278
|
+
fieldklass.def_private("_decrypt_bool", enquo_field_decrypt_bool);
|
238
279
|
fieldklass.def_private("_encrypt_i64", enquo_field_encrypt_i64);
|
239
280
|
fieldklass.def_private("_decrypt_i64", enquo_field_decrypt_i64);
|
240
281
|
fieldklass.def_private("_encrypt_date", enquo_field_encrypt_date);
|
data/lib/enquo/field.rb
CHANGED
@@ -6,6 +6,34 @@ module Enquo
|
|
6
6
|
raise RuntimeError, "Enquo::Field cannot be instantiated directly; use Enquo::Crypto#field instead"
|
7
7
|
end
|
8
8
|
|
9
|
+
def encrypt_bool(b, ctx, safety: true, no_query: false)
|
10
|
+
unless b.is_a?(TrueClass) || b.is_a?(FalseClass)
|
11
|
+
raise ArgumentError, "Enquo::Field#encrypt_bool can only encrypt booleans"
|
12
|
+
end
|
13
|
+
|
14
|
+
unless ctx.is_a?(String)
|
15
|
+
raise ArgumentError, "Encryption context must be a string (got a #{ctx.class})"
|
16
|
+
end
|
17
|
+
|
18
|
+
_encrypt_bool(b, ctx, no_query ? :no_query : safety == :unsafe ? :unsafe : :default)
|
19
|
+
end
|
20
|
+
|
21
|
+
def decrypt_bool(data, ctx)
|
22
|
+
unless data.is_a?(String)
|
23
|
+
raise ArgumentError, "Enquo::Field#decrypt_i64 can only decrypt from a string (got #{data.class})"
|
24
|
+
end
|
25
|
+
|
26
|
+
unless data.encoding == Encoding::UTF_8 && data.valid_encoding?
|
27
|
+
raise ArgumentError, "Enquo::Field#decrypt_i64 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 a #{ctx.class})"
|
32
|
+
end
|
33
|
+
|
34
|
+
_decrypt_bool(data, ctx)
|
35
|
+
end
|
36
|
+
|
9
37
|
def encrypt_i64(i, ctx, safety: true, no_query: false)
|
10
38
|
unless i.is_a?(Integer)
|
11
39
|
raise ArgumentError, "Enquo::Field#encrypt_i64 can only encrypt integers"
|
metadata
CHANGED
@@ -1,15 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enquo-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.0.
|
4
|
+
version: 0.6.0.11.g8d4f25f
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Palmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rb_sys
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.1'
|
27
|
+
force_ruby_platform: false
|
13
28
|
- !ruby/object:Gem::Dependency
|
14
29
|
name: bundler
|
15
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,20 +95,6 @@ dependencies:
|
|
80
95
|
- - "~>"
|
81
96
|
- !ruby/object:Gem::Version
|
82
97
|
version: '1.2'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rb_sys
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0.1'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0.1'
|
97
98
|
- !ruby/object:Gem::Dependency
|
98
99
|
name: redcarpet
|
99
100
|
requirement: !ruby/object:Gem::Requirement
|
@@ -154,7 +155,8 @@ description:
|
|
154
155
|
email:
|
155
156
|
- matt@enquo.org
|
156
157
|
executables: []
|
157
|
-
extensions:
|
158
|
+
extensions:
|
159
|
+
- ext/enquo/extconf.rb
|
158
160
|
extra_rdoc_files: []
|
159
161
|
files:
|
160
162
|
- ".gitignore"
|