capbac 0.4.0 → 0.4.1

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: 44848813257e696a0d0aa3ee32740481dced5a2400821e69a4fe31b130e60476
4
- data.tar.gz: 9e7bc540cba3a4a0be51ed7d91f06455f493dbae694b5a003716d75143196bb5
3
+ metadata.gz: 1bd36669dadaa15cc19abc91afa54f986bce85fe171ed7b9851c8a4bfcdb323d
4
+ data.tar.gz: a9630ec9063f4effef544f22b522b0ecf0da91ba5c3d01f8412d156f6a69911f
5
5
  SHA512:
6
- metadata.gz: 3a05e44960b0368b3fa77def316ead43fd2aef59586ae5900e738b0b1f4f5329fba514270a52cd565301a60ec6c3e1d99cfe596bb52eaa667cd13da6c28999b2
7
- data.tar.gz: 1a30dc257457acd1bb747ab6a4d9452c65d3833aa05459c48a7c61adc73957519516c68e6c21b00683d3ce7f7562cd908ac6542164e9358fa79371babfd7302d
6
+ metadata.gz: 9e60cd11841ba5ea225a4f1e7e7bf6d2ec37ef2ef6fa8ef0ac031431c917c67fc71d09902727b06f041e9c886620e2f85bf285d2e6867aac2e287d9c3a04a621
7
+ data.tar.gz: 3bf141c3eaf5b569a609081061e7b0e72fd8b16f4b1c3cb8f5ac29952524ca54f9f756278174b03cd95ec6d1875c345bbec8ddc92ff42decf9cea8173bc21904
@@ -1,3 +1,3 @@
1
1
  module CapBAC
2
- VERSION = '0.4.0'.freeze
2
+ VERSION = '0.4.1'.freeze
3
3
  end
Binary file
data/src/lib.rs CHANGED
@@ -15,11 +15,51 @@ use ring::{
15
15
  };
16
16
  use rutie::{
17
17
  AnyObject, Boolean, Class, Encoding, Fixnum, Hash, Module, Object, RString, Symbol,
18
- VerifiedObject, GC, VM,
18
+ VerifiedObject, GC, VM, Array,
19
19
  };
20
20
  use std::{fmt, str};
21
21
  use url::Url;
22
22
 
23
+ class!(ASCIIRString);
24
+
25
+ impl VerifiedObject for ASCIIRString {
26
+ fn is_correct_type<T: Object>(object: &T) -> bool {
27
+ object
28
+ .class()
29
+ .ancestors()
30
+ .iter()
31
+ .any(|class| *class == Class::from_existing("String"))
32
+ }
33
+
34
+ fn error_message() -> &'static str {
35
+ "Error converting to ASCII String"
36
+ }
37
+ }
38
+
39
+ impl From<ASCIIRString> for RString {
40
+ fn from(rstring: ASCIIRString) -> Self {
41
+ let bytes = rstring
42
+ .protect_send("bytes", &[])
43
+ .map_err(VM::raise_ex)
44
+ .unwrap()
45
+ .try_convert_to::<Array>()
46
+ .map_err(VM::raise_ex)
47
+ .unwrap();
48
+
49
+ let mut res = Vec::new();
50
+
51
+ for n in bytes.into_iter() {
52
+ let n = n.try_convert_to::<Fixnum>()
53
+ .map_err(|e| VM::raise_ex(e))
54
+ .unwrap();
55
+
56
+ res.push(n.to_i64() as u8);
57
+ }
58
+
59
+ RString::from_bytes(&res, &Encoding::us_ascii())
60
+ }
61
+ }
62
+
23
63
  class!(URI);
24
64
 
25
65
  impl VerifiedObject for URI {
@@ -109,14 +149,12 @@ fn options_to_cert_blueprint(options: Hash) -> CertificateBlueprint {
109
149
  fn options_to_invoke_blueprint(options: Hash) -> InvokeBlueprint {
110
150
  let cert_content = options
111
151
  .at(&Symbol::new("cert"))
112
- .try_convert_to::<RString>()
152
+ .try_convert_to::<ASCIIRString>()
113
153
  .map_err(VM::raise_ex)
114
- .unwrap()
115
- .to_string()
116
- .into_bytes();
154
+ .unwrap();
117
155
 
118
156
  let mut cert = capbac::proto::Certificate::new();
119
- cert.merge_from_bytes(&cert_content).unwrap();
157
+ cert.merge_from_bytes(&RString::from(cert_content).to_vec_u8_unchecked()).unwrap();
120
158
 
121
159
  let action = options
122
160
  .at(&Symbol::new("action"))
@@ -187,15 +225,15 @@ methods!(
187
225
  RString::from_bytes(&cert.write_to_bytes().unwrap(), &Encoding::us_ascii())
188
226
  }
189
227
 
190
- fn ruby_holder_delegate(cert: RString, options: Hash) -> RString {
228
+ fn ruby_holder_delegate(cert: ASCIIRString, options: Hash) -> RString {
191
229
  let ruby_options = options.map_err(VM::raise_ex).unwrap();
192
230
  let options = options_to_cert_blueprint(ruby_options);
193
231
  let holder = itself.get_data(&*HOLDER_WRAPPER);
194
232
 
195
- let cert_content = cert.unwrap().to_string_unchecked();
233
+ let cert_content = RString::from(cert.map_err(VM::raise_ex).unwrap()).to_vec_u8_unchecked();
196
234
 
197
235
  let mut cert = capbac::proto::Certificate::new();
198
- cert.merge_from_bytes(&cert_content.as_bytes()).unwrap();
236
+ cert.merge_from_bytes(&cert_content).unwrap();
199
237
 
200
238
  let cert = holder.delegate(cert, options).unwrap();
201
239
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capbac
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Chernyshov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-24 00:00:00.000000000 Z
11
+ date: 2020-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thermite