enquo-core 0.4.0-aarch64-linux → 0.5.0.1.gab6af4a-aarch64-linux

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14300d7e8d5a6a3122666cd3c7a83686d294373c5537defb60d8531d722cd4eb
4
- data.tar.gz: db807a0c99d1aa1670251261e6918c55cac14b17831f1317607db91d18a19f98
3
+ metadata.gz: 5258e5c597003c2003cb1e22ec0685f2fdcb610fa0d0b0e19f65fd0b9de98fac
4
+ data.tar.gz: a2b97d657a815580c5704ca917e387a928213e78ca98261f73e6e0f28798b582
5
5
  SHA512:
6
- metadata.gz: 50ae282576040722cc4f2fdcb0940ff8728e6edf61ac8c43e02a9d0aaec355245ab7d0d71d137cc9628f698bc28388c4a693aa910f03522a80ecb960ea4053b8
7
- data.tar.gz: 1adcd8c8bc6054d5e8733ac3bd483d675938c73037d91a77af79c7585833be6817b4870566e68b48ee58794db59734eda5558099feb7c8f3f4f5b632fac6705d
6
+ metadata.gz: 379a24e543c577d86995e9bf5d51fff8d03a49d790b281f31f0452a33a2cf925ca79604073c434f09fc76c1342427968dd3fedaecc0a7fb5167b4487d5701d3b
7
+ data.tar.gz: 5b9cf30579d57a69aa19efdadee5f9fe890234ee10db8280de8b0b79e1f26bbb121afaeb23ac0759273fe28ef6cba0b91abca40d84c6236da483c17f8ba9acf4
data/ext/enquo/Cargo.lock CHANGED
@@ -296,6 +296,7 @@ dependencies = [
296
296
  "serde_bytes",
297
297
  "sha2",
298
298
  "thiserror",
299
+ "unicode-normalization",
299
300
  ]
300
301
 
301
302
  [[package]]
@@ -788,6 +789,21 @@ dependencies = [
788
789
  "syn",
789
790
  ]
790
791
 
792
+ [[package]]
793
+ name = "tinyvec"
794
+ version = "1.6.0"
795
+ source = "registry+https://github.com/rust-lang/crates.io-index"
796
+ checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50"
797
+ dependencies = [
798
+ "tinyvec_macros",
799
+ ]
800
+
801
+ [[package]]
802
+ name = "tinyvec_macros"
803
+ version = "0.1.0"
804
+ source = "registry+https://github.com/rust-lang/crates.io-index"
805
+ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
806
+
791
807
  [[package]]
792
808
  name = "typenum"
793
809
  version = "1.15.0"
@@ -800,6 +816,15 @@ version = "1.0.3"
800
816
  source = "registry+https://github.com/rust-lang/crates.io-index"
801
817
  checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf"
802
818
 
819
+ [[package]]
820
+ name = "unicode-normalization"
821
+ version = "0.1.22"
822
+ source = "registry+https://github.com/rust-lang/crates.io-index"
823
+ checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921"
824
+ dependencies = [
825
+ "tinyvec",
826
+ ]
827
+
803
828
  [[package]]
804
829
  name = "unicode-width"
805
830
  version = "0.1.9"
data/ext/enquo/src/lib.rs CHANGED
@@ -1,17 +1,19 @@
1
1
  #[macro_use]
2
2
  extern crate rutie;
3
3
 
4
- use enquo_core::{Date, Field, Root, I64};
4
+ use enquo_core::{key_provider, Date, Field, Root, Text, I64};
5
5
  use rutie::{AnyObject, Class, Integer, Module, Object, RString, Symbol, VerifiedObject, VM};
6
6
 
7
7
  class!(EnquoRoot);
8
8
  class!(EnquoRootKeyStatic);
9
9
  class!(EnquoField);
10
10
 
11
- type StaticRootKey = Vec<u8>;
12
-
13
11
  wrappable_struct!(Root<'static>, RootWrapper, ROOT_WRAPPER);
14
- wrappable_struct!(StaticRootKey, StaticRootKeyWrapper, STATIC_ROOT_KEY_WRAPPER);
12
+ wrappable_struct!(
13
+ key_provider::Static,
14
+ StaticRootKeyWrapper,
15
+ STATIC_ROOT_KEY_WRAPPER
16
+ );
15
17
  wrappable_struct!(Field, FieldWrapper, FIELD_WRAPPER);
16
18
 
17
19
  fn maybe_raise<T, E: std::error::Error>(r: Result<T, E>, s: &str) -> T {
@@ -24,27 +26,24 @@ fn maybe_raise<T, E: std::error::Error>(r: Result<T, E>, s: &str) -> T {
24
26
  .unwrap()
25
27
  }
26
28
 
27
- methods!(
29
+ unsafe_methods!(
28
30
  EnquoRoot,
29
31
  rbself,
30
32
  fn enquo_root_new_from_static_root_key(root_key_obj: EnquoRootKeyStatic) -> EnquoRoot {
31
- let root_key = root_key_obj.unwrap();
32
- // Not so needless after all, Clippy...
33
- #[allow(clippy::needless_borrow)]
34
- let rk = root_key.get_data(&*STATIC_ROOT_KEY_WRAPPER);
33
+ let rk = root_key_obj.get_data(&*STATIC_ROOT_KEY_WRAPPER);
35
34
  let root = maybe_raise(Root::new(rk), "Failed to create Enquo::Root");
36
35
 
37
36
  let klass = Module::from_existing("Enquo").get_nested_class("Root");
38
37
  klass.wrap_data(root, &*ROOT_WRAPPER)
39
38
  },
40
- fn enquo_root_field(relation: RString, name: RString) -> EnquoField {
39
+ fn enquo_root_field(relation_obj: RString, name_obj: RString) -> EnquoField {
40
+ let relation = relation_obj.to_vec_u8_unchecked();
41
+ let name = name_obj.to_vec_u8_unchecked();
42
+
41
43
  let root = rbself.get_data(&*ROOT_WRAPPER);
42
44
 
43
45
  let field = maybe_raise(
44
- root.field(
45
- &relation.unwrap().to_vec_u8_unchecked(),
46
- &name.unwrap().to_vec_u8_unchecked(),
47
- ),
46
+ root.field(&relation, &name),
48
47
  "Failed to create Enquo::Field",
49
48
  );
50
49
 
@@ -53,12 +52,13 @@ methods!(
53
52
  }
54
53
  );
55
54
 
56
- methods!(
55
+ unsafe_methods!(
57
56
  EnquoRootKeyStatic,
58
57
  _rbself,
59
- fn enquo_root_key_static_new(root_key: RString) -> EnquoRootKeyStatic {
60
- #[allow(clippy::redundant_clone)]
61
- let k = root_key.unwrap().to_vec_u8_unchecked().to_owned();
58
+ fn enquo_root_key_static_new(root_key_obj: RString) -> EnquoRootKeyStatic {
59
+ let root_key = root_key_obj.to_vec_u8_unchecked();
60
+
61
+ let k = key_provider::Static::new(&root_key);
62
62
  let klass = Module::from_existing("Enquo")
63
63
  .get_nested_class("RootKey")
64
64
  .get_nested_class("Static");
@@ -81,85 +81,90 @@ impl VerifiedObject for EnquoRootKeyStatic {
81
81
 
82
82
  // rustfmt fucks this so it doesn't compile
83
83
  #[rustfmt::skip]
84
- methods!(
84
+ unsafe_methods!(
85
85
  EnquoField,
86
86
  rbself,
87
- fn enquo_field_encrypt_i64(value: Integer, context: RString, mode: Symbol) -> RString {
88
- let i = value.unwrap().to_i64();
87
+ fn enquo_field_encrypt_i64(i_obj: Integer, context_obj: RString, mode_obj: Symbol) -> RString {
88
+ let i = i_obj.to_i64();
89
+ let context = context_obj.to_vec_u8_unchecked();
90
+ let mode = mode_obj.to_str();
91
+
89
92
  let field = rbself.get_data(&*FIELD_WRAPPER);
90
- let r_mode = mode.unwrap();
91
- let s_mode = r_mode.to_str();
92
93
 
93
94
  let mut res = maybe_raise(
94
- if s_mode == "unsafe" {
95
- I64::new_with_unsafe_parts(i, &context.unwrap().to_vec_u8_unchecked(), field)
95
+ if mode == "unsafe" {
96
+ I64::new_with_unsafe_parts(i, &context, field)
96
97
  } else {
97
- I64::new(i, &context.unwrap().to_vec_u8_unchecked(), field)
98
+ I64::new(i, &context, field)
98
99
  },
99
100
  "Failed to create encrypted i64",
100
101
  );
101
- if s_mode == "no_query" {
102
+ if mode == "no_query" {
102
103
  res.drop_ore_ciphertext();
103
104
  }
104
105
 
105
- RString::new_utf8(&serde_json::to_string(&res).unwrap())
106
+ RString::new_utf8(&maybe_raise(serde_json::to_string(&res), "Failed to JSONify ciphertext"))
106
107
  },
107
- fn enquo_field_decrypt_i64(ciphertext: RString, context: RString) -> Integer {
108
- let ct_r = ciphertext.unwrap();
109
- let ct = ct_r.to_str_unchecked();
108
+ fn enquo_field_decrypt_i64(ciphertext_obj: RString, context_obj: RString) -> Integer {
109
+ let ct = ciphertext_obj.to_str_unchecked();
110
+ let context = context_obj.to_vec_u8_unchecked();
111
+
112
+ let field = rbself.get_data(&*FIELD_WRAPPER);
113
+
110
114
  let e_value: I64 =
111
115
  maybe_raise(serde_json::from_str(ct), "Failed to deserialize ciphertext");
112
116
 
113
- let field = rbself.get_data(&*FIELD_WRAPPER);
114
117
 
115
118
  let value = maybe_raise(
116
- e_value.decrypt(&context.unwrap().to_vec_u8_unchecked(), field),
119
+ e_value.decrypt(&context, field),
117
120
  "Failed to decrypt i64 value",
118
121
  );
119
122
  Integer::from(value)
120
123
  },
121
124
  fn enquo_field_encrypt_date(
122
- y_r: Integer,
123
- m_r: Integer,
124
- d_r: Integer,
125
- context: RString,
126
- mode: Symbol
125
+ y_obj: Integer,
126
+ m_obj: Integer,
127
+ d_obj: Integer,
128
+ context_obj: RString,
129
+ mode_obj: Symbol
127
130
  ) -> RString {
128
- let y = y_r.unwrap().to_i32() as i16;
129
- let m = m_r.unwrap().to_i32() as u8;
130
- let d = d_r.unwrap().to_i32() as u8;
131
+ let y = y_obj.to_i32() as i16;
132
+ let m = m_obj.to_i32() as u8;
133
+ let d = d_obj.to_i32() as u8;
134
+ let context = context_obj.to_vec_u8_unchecked();
135
+ let mode = mode_obj.to_str();
136
+
131
137
  let field = rbself.get_data(&*FIELD_WRAPPER);
132
- let r_mode = mode.unwrap();
133
- let s_mode = r_mode.to_str();
134
138
 
135
139
  let mut res = maybe_raise(
136
- if s_mode == "unsafe" {
140
+ if mode == "unsafe" {
137
141
  Date::new_with_unsafe_parts(
138
142
  (y, m, d),
139
- &context.unwrap().to_vec_u8_unchecked(),
143
+ &context,
140
144
  field,
141
145
  )
142
146
  } else {
143
- Date::new((y, m, d), &context.unwrap().to_vec_u8_unchecked(), field)
147
+ Date::new((y, m, d), &context, field)
144
148
  },
145
149
  "Failed to create encrypted date",
146
150
  );
147
- if s_mode == "no_query" {
151
+ if mode == "no_query" {
148
152
  res.drop_ore_ciphertexts();
149
153
  }
150
154
 
151
- RString::new_utf8(&serde_json::to_string(&res).unwrap())
155
+ RString::new_utf8(&maybe_raise(serde_json::to_string(&res), "Failed to JSONify ciphertext"))
152
156
  },
153
- fn enquo_field_decrypt_date(ciphertext: RString, context: RString) -> AnyObject {
154
- let ct_r = ciphertext.unwrap();
155
- let ct = ct_r.to_str_unchecked();
156
- let e_value: Date =
157
- maybe_raise(serde_json::from_str(ct), "Failed to deserialize ciphertext");
157
+ fn enquo_field_decrypt_date(ciphertext_obj: RString, context_obj: RString) -> AnyObject {
158
+ let ct = ciphertext_obj.to_str_unchecked();
159
+ let context = context_obj.to_vec_u8_unchecked();
158
160
 
159
161
  let field = rbself.get_data(&*FIELD_WRAPPER);
160
162
 
163
+ let e_value: Date =
164
+ maybe_raise(serde_json::from_str(ct), "Failed to deserialize ciphertext");
165
+
161
166
  let (y, m, d) = maybe_raise(
162
- e_value.decrypt(&context.unwrap().to_vec_u8_unchecked(), field),
167
+ e_value.decrypt(&context, field),
163
168
  "Failed to decrypt date value",
164
169
  );
165
170
  let klass = Class::from_existing("Date");
@@ -170,6 +175,48 @@ methods!(
170
175
  ];
171
176
  klass.protect_send("new", &args).unwrap()
172
177
  }
178
+ fn enquo_field_encrypt_text(
179
+ text_obj: RString,
180
+ context_obj: RString,
181
+ mode_obj: Symbol
182
+ ) -> RString {
183
+ let text = text_obj.to_str();
184
+ let context = context_obj.to_vec_u8_unchecked();
185
+ let mode = mode_obj.to_str();
186
+
187
+ let field = rbself.get_data(&*FIELD_WRAPPER);
188
+
189
+ let mut res = maybe_raise(
190
+ if mode == "unsafe" {
191
+ Text::new_with_unsafe_parts(
192
+ text,
193
+ &context,
194
+ field,
195
+ )
196
+ } else {
197
+ Text::new(text, &context, field)
198
+ },
199
+ "Failed to create encrypted date",
200
+ );
201
+ if mode == "no_query" {
202
+ res.make_unqueryable();
203
+ }
204
+
205
+ RString::new_utf8(&maybe_raise(serde_json::to_string(&res), "Failed to JSONify ciphertext"))
206
+ },
207
+ fn enquo_field_decrypt_text(ciphertext_obj: RString, context_obj: RString) -> RString {
208
+ let ct = ciphertext_obj.to_str_unchecked();
209
+ let context = context_obj.to_vec_u8_unchecked();
210
+
211
+ let field = rbself.get_data(&*FIELD_WRAPPER);
212
+
213
+ let e_value: Text =
214
+ maybe_raise(serde_json::from_str(ct), "Failed to deserialize ciphertext");
215
+
216
+ let s = maybe_raise(e_value.decrypt(&context, field), "Failed to decrypt text value");
217
+
218
+ RString::new_utf8(&s)
219
+ }
173
220
  );
174
221
 
175
222
  #[allow(non_snake_case)]
@@ -192,6 +239,8 @@ pub extern "C" fn Init_enquo() {
192
239
  fieldklass.def_private("_decrypt_i64", enquo_field_decrypt_i64);
193
240
  fieldklass.def_private("_encrypt_date", enquo_field_encrypt_date);
194
241
  fieldklass.def_private("_decrypt_date", enquo_field_decrypt_date);
242
+ fieldklass.def_private("_encrypt_text", enquo_field_encrypt_text);
243
+ fieldklass.def_private("_decrypt_text", enquo_field_decrypt_text);
195
244
  });
196
245
  topmod.define_nested_module("RootKey").define(|rkmod| {
197
246
  rkmod
data/lib/2.7/enquo.so CHANGED
Binary file
data/lib/3.0/enquo.so CHANGED
Binary file
data/lib/3.1/enquo.so CHANGED
Binary file
data/lib/enquo/field.rb CHANGED
@@ -69,5 +69,41 @@ module Enquo
69
69
 
70
70
  _decrypt_date(data, ctx)
71
71
  end
72
+
73
+ def encrypt_text(t, ctx, safety: true, no_query: false)
74
+ unless t.is_a?(String)
75
+ raise ArgumentError, "Enquo::Field#encrypt_string can only encrypt Strings"
76
+ end
77
+
78
+ unless t.encoding == Encoding::UTF_8
79
+ raise ArgumentError, "Enquo::Field#encrypt_string can only encrypt UTF-8 strings (got a string encoding of #{t.encoding})"
80
+ end
81
+
82
+ unless t.valid_encoding?
83
+ raise ArgumentError, "Enquo::Field#encrypt_string can only encrypt validly-encoded UTF-8 strings"
84
+ end
85
+
86
+ unless ctx.is_a?(String)
87
+ raise ArgumentError, "Encryption context must be a string (got a #{ctx.class})"
88
+ end
89
+
90
+ _encrypt_text(t, ctx, no_query ? :no_query : safety == :unsafe ? :unsafe : :default)
91
+ end
92
+
93
+ def decrypt_text(data, ctx)
94
+ unless data.is_a?(String)
95
+ raise ArgumentError, "Enquo::Field#decrypt_text can only decrypt from a string (got #{data.class})"
96
+ end
97
+
98
+ unless data.encoding == Encoding::UTF_8 && data.valid_encoding?
99
+ raise ArgumentError, "Enquo::Field#decrypt_date can only decrypt validly-encoded UTF-8 strings (got #{data.encoding})"
100
+ end
101
+
102
+ unless ctx.is_a?(String)
103
+ raise ArgumentError, "Encryption context must be a string (got a #{ctx.class})"
104
+ end
105
+
106
+ _decrypt_text(data, ctx)
107
+ end
72
108
  end
73
109
  end
data/lib/enquo/root.rb CHANGED
@@ -6,6 +6,10 @@ module Enquo
6
6
  _new_from_static_root_key(key)
7
7
  else
8
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)
9
13
  end
10
14
  end
11
15
 
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.4.0
4
+ version: 0.5.0.1.gab6af4a
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Matt Palmer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-04 00:00:00.000000000 Z
11
+ date: 2022-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -193,9 +193,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
193
193
  version: 3.2.dev
194
194
  required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  requirements:
196
- - - ">="
196
+ - - ">"
197
197
  - !ruby/object:Gem::Version
198
- version: '0'
198
+ version: 1.3.1
199
199
  requirements: []
200
200
  rubygems_version: 3.3.22
201
201
  signing_key: