rb_mumble_protocol 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Cargo.lock +46 -35
- data/ext/rb_mumble_protocol/Cargo.toml +2 -2
- data/ext/rb_mumble_protocol/src/lib.rs +94 -41
- data/lib/rb_mumble_protocol/crypt_state.rb +3 -0
- data/lib/rb_mumble_protocol/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3cb4a478bc0cc5d8928902a1d4905d59182051d8c5666f70b6ae31f393b06d91
|
4
|
+
data.tar.gz: 26b9deba5193c57621d82665857702b15c19ba61fa4960983dddecd04cca2b94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 397a5909f8ab0cca9fd0c303dc832e8888850811df1228eb0330c0430da1c568367da96d470271b36b243e82b5801ef2aa44e9f4e6b2cdf808659822bda8ccaf
|
7
|
+
data.tar.gz: 030e4c96656cbb4ac7f4401275dde69633ac0d0ff648478b62b7409b84f1b957ec37259d4db79f25073d75dc9bd808d96de96bf3d800e536f29fc7cc2185c9f4
|
data/Cargo.lock
CHANGED
@@ -13,22 +13,22 @@ dependencies = [
|
|
13
13
|
|
14
14
|
[[package]]
|
15
15
|
name = "bindgen"
|
16
|
-
version = "0.
|
16
|
+
version = "0.69.4"
|
17
17
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
18
|
-
checksum = "
|
18
|
+
checksum = "a00dc851838a2120612785d195287475a3ac45514741da670b735818822129a0"
|
19
19
|
dependencies = [
|
20
|
-
"bitflags",
|
20
|
+
"bitflags 2.4.2",
|
21
21
|
"cexpr",
|
22
22
|
"clang-sys",
|
23
|
+
"itertools",
|
23
24
|
"lazy_static",
|
24
25
|
"lazycell",
|
25
|
-
"peeking_take_while",
|
26
26
|
"proc-macro2",
|
27
27
|
"quote",
|
28
28
|
"regex",
|
29
29
|
"rustc-hash",
|
30
30
|
"shlex",
|
31
|
-
"syn
|
31
|
+
"syn",
|
32
32
|
]
|
33
33
|
|
34
34
|
[[package]]
|
@@ -37,6 +37,12 @@ version = "1.3.2"
|
|
37
37
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
38
38
|
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
39
39
|
|
40
|
+
[[package]]
|
41
|
+
name = "bitflags"
|
42
|
+
version = "2.4.2"
|
43
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
44
|
+
checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf"
|
45
|
+
|
40
46
|
[[package]]
|
41
47
|
name = "bytes"
|
42
48
|
version = "1.4.0"
|
@@ -75,6 +81,12 @@ dependencies = [
|
|
75
81
|
"libloading",
|
76
82
|
]
|
77
83
|
|
84
|
+
[[package]]
|
85
|
+
name = "either"
|
86
|
+
version = "1.9.0"
|
87
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
88
|
+
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
|
89
|
+
|
78
90
|
[[package]]
|
79
91
|
name = "foreign-types"
|
80
92
|
version = "0.3.2"
|
@@ -96,6 +108,15 @@ version = "0.3.1"
|
|
96
108
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
97
109
|
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
|
98
110
|
|
111
|
+
[[package]]
|
112
|
+
name = "itertools"
|
113
|
+
version = "0.12.1"
|
114
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
115
|
+
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
|
116
|
+
dependencies = [
|
117
|
+
"either",
|
118
|
+
]
|
119
|
+
|
99
120
|
[[package]]
|
100
121
|
name = "lazy_static"
|
101
122
|
version = "1.4.0"
|
@@ -126,24 +147,25 @@ dependencies = [
|
|
126
147
|
|
127
148
|
[[package]]
|
128
149
|
name = "magnus"
|
129
|
-
version = "0.
|
150
|
+
version = "0.6.2"
|
130
151
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
131
|
-
checksum = "
|
152
|
+
checksum = "4778544796676e8428e9c622460ebf284bea52d8b10db3aeb449d8b5e61b3a13"
|
132
153
|
dependencies = [
|
133
154
|
"magnus-macros",
|
134
155
|
"rb-sys",
|
135
156
|
"rb-sys-env",
|
157
|
+
"seq-macro",
|
136
158
|
]
|
137
159
|
|
138
160
|
[[package]]
|
139
161
|
name = "magnus-macros"
|
140
|
-
version = "0.
|
162
|
+
version = "0.6.0"
|
141
163
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
142
|
-
checksum = "
|
164
|
+
checksum = "5968c820e2960565f647819f5928a42d6e874551cab9d88d75e3e0660d7f71e3"
|
143
165
|
dependencies = [
|
144
166
|
"proc-macro2",
|
145
167
|
"quote",
|
146
|
-
"syn
|
168
|
+
"syn",
|
147
169
|
]
|
148
170
|
|
149
171
|
[[package]]
|
@@ -180,7 +202,7 @@ version = "0.10.55"
|
|
180
202
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
181
203
|
checksum = "345df152bc43501c5eb9e4654ff05f794effb78d4efe3d53abc158baddc0703d"
|
182
204
|
dependencies = [
|
183
|
-
"bitflags",
|
205
|
+
"bitflags 1.3.2",
|
184
206
|
"cfg-if",
|
185
207
|
"foreign-types",
|
186
208
|
"libc",
|
@@ -197,7 +219,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
|
|
197
219
|
dependencies = [
|
198
220
|
"proc-macro2",
|
199
221
|
"quote",
|
200
|
-
"syn
|
222
|
+
"syn",
|
201
223
|
]
|
202
224
|
|
203
225
|
[[package]]
|
@@ -212,12 +234,6 @@ dependencies = [
|
|
212
234
|
"vcpkg",
|
213
235
|
]
|
214
236
|
|
215
|
-
[[package]]
|
216
|
-
name = "peeking_take_while"
|
217
|
-
version = "0.1.2"
|
218
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
219
|
-
checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099"
|
220
|
-
|
221
237
|
[[package]]
|
222
238
|
name = "pkg-config"
|
223
239
|
version = "0.3.27"
|
@@ -244,18 +260,18 @@ dependencies = [
|
|
244
260
|
|
245
261
|
[[package]]
|
246
262
|
name = "rb-sys"
|
247
|
-
version = "0.9.
|
263
|
+
version = "0.9.87"
|
248
264
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
249
|
-
checksum = "
|
265
|
+
checksum = "225103e3d69bbfe8831f9fd0d2461335f3a9dd06aa6e88bcb6d6970383494d06"
|
250
266
|
dependencies = [
|
251
267
|
"rb-sys-build",
|
252
268
|
]
|
253
269
|
|
254
270
|
[[package]]
|
255
271
|
name = "rb-sys-build"
|
256
|
-
version = "0.9.
|
272
|
+
version = "0.9.87"
|
257
273
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
258
|
-
checksum = "
|
274
|
+
checksum = "bacce8095a5167d5ede618bbd9353e9d9e2f32ddaf54be911106f0ee6baacf09"
|
259
275
|
dependencies = [
|
260
276
|
"bindgen",
|
261
277
|
"lazy_static",
|
@@ -263,7 +279,7 @@ dependencies = [
|
|
263
279
|
"quote",
|
264
280
|
"regex",
|
265
281
|
"shell-words",
|
266
|
-
"syn
|
282
|
+
"syn",
|
267
283
|
]
|
268
284
|
|
269
285
|
[[package]]
|
@@ -274,7 +290,7 @@ checksum = "a35802679f07360454b418a5d1735c89716bde01d35b1560fc953c1415a0b3bb"
|
|
274
290
|
|
275
291
|
[[package]]
|
276
292
|
name = "rb_mumble_protocol"
|
277
|
-
version = "0.
|
293
|
+
version = "0.2.0"
|
278
294
|
dependencies = [
|
279
295
|
"bytes",
|
280
296
|
"magnus",
|
@@ -316,6 +332,12 @@ version = "1.1.0"
|
|
316
332
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
317
333
|
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
318
334
|
|
335
|
+
[[package]]
|
336
|
+
name = "seq-macro"
|
337
|
+
version = "0.3.5"
|
338
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
339
|
+
checksum = "a3f0bf26fd526d2a95683cd0f87bf103b8539e2ca1ef48ce002d67aad59aa0b4"
|
340
|
+
|
319
341
|
[[package]]
|
320
342
|
name = "shell-words"
|
321
343
|
version = "1.1.0"
|
@@ -328,17 +350,6 @@ version = "1.1.0"
|
|
328
350
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
329
351
|
checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3"
|
330
352
|
|
331
|
-
[[package]]
|
332
|
-
name = "syn"
|
333
|
-
version = "1.0.109"
|
334
|
-
source = "registry+https://github.com/rust-lang/crates.io-index"
|
335
|
-
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
|
336
|
-
dependencies = [
|
337
|
-
"proc-macro2",
|
338
|
-
"quote",
|
339
|
-
"unicode-ident",
|
340
|
-
]
|
341
|
-
|
342
353
|
[[package]]
|
343
354
|
name = "syn"
|
344
355
|
version = "2.0.27"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
[package]
|
2
2
|
name = "rb_mumble_protocol"
|
3
|
-
version = "0.
|
3
|
+
version = "0.2.0"
|
4
4
|
edition = "2021"
|
5
5
|
authors = ["Mikhail Odebe <derpiranha@gmail.com>"]
|
6
6
|
publish = false
|
@@ -9,6 +9,6 @@ publish = false
|
|
9
9
|
crate-type = ["cdylib"]
|
10
10
|
|
11
11
|
[dependencies]
|
12
|
-
magnus = { version = "0.
|
12
|
+
magnus = { version = "0.6" }
|
13
13
|
bytes = "1.0"
|
14
14
|
openssl = { version = "0.10" }
|
@@ -1,12 +1,33 @@
|
|
1
1
|
use std::cell::RefCell;
|
2
2
|
|
3
|
-
use magnus::{
|
3
|
+
use magnus::{
|
4
|
+
class, define_module,
|
5
|
+
method, function, prelude::*,
|
6
|
+
Error, RHash, RModule, Ruby,
|
7
|
+
value::{Lazy},
|
8
|
+
exception::ExceptionClass,
|
9
|
+
gc::register_mark_object,
|
10
|
+
};
|
4
11
|
|
5
12
|
use bytes::BytesMut;
|
6
13
|
|
14
|
+
static BASE_ERROR: Lazy<ExceptionClass> = Lazy::new(|ruby| {
|
15
|
+
let ex = ruby
|
16
|
+
.class_object()
|
17
|
+
.const_get::<_, RModule>("RbMumbleProtocol")
|
18
|
+
.unwrap()
|
19
|
+
.const_get("Error")
|
20
|
+
.unwrap();
|
21
|
+
|
22
|
+
// ensure `ex` is never garbage collected (e.g. if constant is
|
23
|
+
// redefined) and also not moved under compacting GC.
|
24
|
+
register_mark_object(ex);
|
25
|
+
ex
|
26
|
+
});
|
27
|
+
|
7
28
|
pub mod crypt_state;
|
8
29
|
|
9
|
-
#[magnus::wrap(class = "RbMumbleProtocol::CryptState"
|
30
|
+
#[magnus::wrap(class = "RbMumbleProtocol::CryptState")]
|
10
31
|
struct CryptStateRef(RefCell<crypt_state::CryptState>);
|
11
32
|
|
12
33
|
impl CryptStateRef {
|
@@ -43,39 +64,88 @@ impl CryptStateRef {
|
|
43
64
|
Self(RefCell::new(new_state))
|
44
65
|
}
|
45
66
|
|
46
|
-
pub fn key(&self) -> Vec<u8> {
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
let hash = RHash::new();
|
52
|
-
let state = self.0.try_borrow_mut().unwrap();
|
53
|
-
|
54
|
-
let _ = hash.aset("good", state.get_good());
|
55
|
-
let _ = hash.aset("late", state.get_late());
|
56
|
-
let _ = hash.aset("lost", state.get_lost());
|
57
|
-
|
58
|
-
hash
|
67
|
+
pub fn key(&self) -> Result<Vec<u8>, Error> {
|
68
|
+
match self.0.try_borrow() {
|
69
|
+
Ok(ref_) => { Ok(ref_.get_key().to_vec()) },
|
70
|
+
Err(_e) => { Err(Error::new(get_ruby().get_inner(&BASE_ERROR), "borrow error")) }
|
71
|
+
}
|
59
72
|
}
|
60
73
|
|
61
|
-
pub fn
|
62
|
-
|
74
|
+
pub fn encrypt_nonce(&self) -> Result<Vec<u8>, Error> {
|
75
|
+
match self.0.try_borrow() {
|
76
|
+
Ok(ref_) => { Ok(ref_.get_encrypt_nonce().to_vec()) },
|
77
|
+
Err(_e) => { Err(Error::new(get_ruby().get_inner(&BASE_ERROR), "borrow error")) }
|
78
|
+
}
|
79
|
+
}
|
63
80
|
|
64
|
-
|
81
|
+
pub fn decrypt_nonce(&self) -> Result<Vec<u8>, Error> {
|
82
|
+
match self.0.try_borrow() {
|
83
|
+
Ok(ref_) => { Ok(ref_.get_decrypt_nonce().to_vec()) },
|
84
|
+
Err(_e) => { Err(Error::new(get_ruby().get_inner(&BASE_ERROR), "borrow error")) }
|
85
|
+
}
|
86
|
+
}
|
65
87
|
|
66
|
-
|
88
|
+
pub fn stats(&self) -> Result<RHash, Error> {
|
89
|
+
match self.0.try_borrow() {
|
90
|
+
Ok(state) => {
|
91
|
+
let hash = RHash::new();
|
92
|
+
|
93
|
+
let _ = hash.aset("good", state.get_good());
|
94
|
+
let _ = hash.aset("late", state.get_late());
|
95
|
+
let _ = hash.aset("lost", state.get_lost());
|
96
|
+
|
97
|
+
Ok(hash)
|
98
|
+
},
|
99
|
+
Err(_e) => {
|
100
|
+
Err(Error::new(get_ruby().get_inner(&BASE_ERROR), "borrow error"))
|
101
|
+
}
|
102
|
+
}
|
67
103
|
}
|
68
104
|
|
69
|
-
pub fn
|
70
|
-
|
71
|
-
|
105
|
+
pub fn encrypt(&self, src: Vec<u8>) -> Result<Vec<u8>, Error> {
|
106
|
+
match self.0.try_borrow_mut() {
|
107
|
+
Ok(mut state) => {
|
108
|
+
let mut buffer = BytesMut::new();
|
109
|
+
state.encrypt(src, &mut buffer);
|
72
110
|
|
73
|
-
|
111
|
+
Ok(buffer.to_vec())
|
112
|
+
},
|
113
|
+
Err(_e) => { Err(Error::new(get_ruby().get_inner(&BASE_ERROR), "borrow error")) }
|
114
|
+
}
|
115
|
+
}
|
74
116
|
|
75
|
-
|
117
|
+
pub fn decrypt(&self, encrypted: Vec<u8>) -> Result<Vec<u8>, Error> {
|
118
|
+
match self.0.try_borrow_mut() {
|
119
|
+
Ok(mut state) => {
|
120
|
+
let mut buffer = BytesMut::new();
|
121
|
+
buffer.extend_from_slice(&encrypted);
|
122
|
+
|
123
|
+
match state.decrypt(&mut buffer) {
|
124
|
+
Ok(_) => Ok(buffer.to_vec()),
|
125
|
+
Err(crypt_state::DecryptError::Repeat) => {
|
126
|
+
Err(Error::new(get_ruby().get_inner(&BASE_ERROR), "DecryptError::Repeat"))
|
127
|
+
},
|
128
|
+
Err(crypt_state::DecryptError::Late) => {
|
129
|
+
Err(Error::new(get_ruby().get_inner(&BASE_ERROR), "DecryptError::Late"))
|
130
|
+
},
|
131
|
+
Err(crypt_state::DecryptError::Mac) => {
|
132
|
+
Err(Error::new(get_ruby().get_inner(&BASE_ERROR), "DecryptError::Mac"))
|
133
|
+
},
|
134
|
+
Err(crypt_state::DecryptError::Eof) => {
|
135
|
+
Err(Error::new(get_ruby().get_inner(&BASE_ERROR), "DecryptError::Eof"))
|
136
|
+
}
|
137
|
+
}
|
138
|
+
},
|
139
|
+
Err(_e) => { Err(Error::new(get_ruby().get_inner(&BASE_ERROR), "borrow error")) }
|
140
|
+
}
|
76
141
|
}
|
77
142
|
}
|
78
143
|
|
144
|
+
#[inline]
|
145
|
+
fn get_ruby() -> Ruby {
|
146
|
+
unsafe { Ruby::get_unchecked() }
|
147
|
+
}
|
148
|
+
|
79
149
|
#[magnus::init]
|
80
150
|
fn init() -> Result<(), Error> {
|
81
151
|
let module = define_module("RbMumbleProtocol")?;
|
@@ -94,20 +164,3 @@ fn init() -> Result<(), Error> {
|
|
94
164
|
|
95
165
|
Ok(())
|
96
166
|
}
|
97
|
-
|
98
|
-
#[test]
|
99
|
-
fn encrypt_and_decrypt_are_inverse() {
|
100
|
-
let server_state = CryptStateRef::new();
|
101
|
-
// swap nonce vectors side to side
|
102
|
-
let client_state = CryptStateRef::new_from(
|
103
|
-
server_state.key(),
|
104
|
-
server_state.decrypt_nonce(),
|
105
|
-
server_state.encrypt_nonce()
|
106
|
-
);
|
107
|
-
|
108
|
-
let src= "test".as_bytes().to_vec();
|
109
|
-
let encrypted= server_state.encrypt(src.clone());
|
110
|
-
let result= client_state.decrypt(encrypted.clone());
|
111
|
-
|
112
|
-
assert_eq!(src, result);
|
113
|
-
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rb_mumble_protocol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikhail Odebe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Gem that providing classes for implementing Mumble-related projects.
|
14
14
|
email:
|