rb_mumble_protocol 0.2.0 → 0.3.0

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: 3cb4a478bc0cc5d8928902a1d4905d59182051d8c5666f70b6ae31f393b06d91
4
- data.tar.gz: 26b9deba5193c57621d82665857702b15c19ba61fa4960983dddecd04cca2b94
3
+ metadata.gz: 7389a940b90f092d9f0b0450ed5ae3237e93f3c6d9400a799e6f6221a63e330a
4
+ data.tar.gz: 7332e0fec01c75d7845ac315d05a0b018fbadbb248b3553aa1b12ff2cf3a70eb
5
5
  SHA512:
6
- metadata.gz: 397a5909f8ab0cca9fd0c303dc832e8888850811df1228eb0330c0430da1c568367da96d470271b36b243e82b5801ef2aa44e9f4e6b2cdf808659822bda8ccaf
7
- data.tar.gz: 030e4c96656cbb4ac7f4401275dde69633ac0d0ff648478b62b7409b84f1b957ec37259d4db79f25073d75dc9bd808d96de96bf3d800e536f29fc7cc2185c9f4
6
+ metadata.gz: '09a342f7767ac3e1410bbb05c4bf38b6450052d6656c64697d49e1b1b980e426263c899247c3c6364a60ce4bdd61e758a290fa3d640c7c39a6b95a724ac0488d'
7
+ data.tar.gz: 43b4a05ac99e5ef55db0c7c53e723fe40ee22ba2a7e69b86cf373435b6785cf30a089e17a33ebcecde6eac314448b0ae84b4161eba1a9cb219533da6b2f32461
data/Cargo.toml CHANGED
@@ -4,4 +4,4 @@
4
4
 
5
5
  [workspace]
6
6
  members = ["./ext/rb_mumble_protocol"]
7
- # resolver = "2"
7
+ resolver = "1"
@@ -27,9 +27,55 @@ static BASE_ERROR: Lazy<ExceptionClass> = Lazy::new(|ruby| {
27
27
 
28
28
  pub mod crypt_state;
29
29
 
30
- #[magnus::wrap(class = "RbMumbleProtocol::CryptState")]
30
+ use crypt_state::{DecryptError};
31
+
32
+ impl Into<u8> for DecryptError {
33
+ fn into(self: DecryptError) -> u8 {
34
+ match self {
35
+ DecryptError::Repeat => 1,
36
+ DecryptError::Late => 2,
37
+ DecryptError::Mac => 3,
38
+ DecryptError::Eof => 4
39
+ }
40
+ }
41
+ }
42
+
43
+ #[magnus::wrap(class = "RbMumbleProtocol::CryptState", size)]
31
44
  struct CryptStateRef(RefCell<crypt_state::CryptState>);
32
45
 
46
+ #[magnus::wrap(class = "RbMumbleProtocol::DecryptResult", free_immediately, size)]
47
+ struct DecryptResult {
48
+ buffer: RefCell<Vec<u8>>,
49
+ reason_raw: u8
50
+ }
51
+
52
+ impl DecryptResult {
53
+ pub fn new(buffer: Vec<u8>, result: Result<(), DecryptError>) -> Self {
54
+ let reason_raw =
55
+ match result {
56
+ Ok(()) => 0,
57
+ Err(e) => e.into()
58
+ };
59
+
60
+ Self {
61
+ buffer: RefCell::new(buffer),
62
+ reason_raw: reason_raw.into()
63
+ }
64
+ }
65
+
66
+ pub fn is_success(&self) -> bool {
67
+ self.reason_raw == 0
68
+ }
69
+
70
+ pub fn data(&self) -> Vec<u8> {
71
+ self.buffer.borrow().to_vec()
72
+ }
73
+
74
+ pub fn reason_raw_value(&self) -> u8 {
75
+ self.reason_raw
76
+ }
77
+ }
78
+
33
79
  impl CryptStateRef {
34
80
  pub fn new() -> Self {
35
81
  Self(RefCell::new(crypt_state::CryptState::generate_new()))
@@ -114,27 +160,14 @@ impl CryptStateRef {
114
160
  }
115
161
  }
116
162
 
117
- pub fn decrypt(&self, encrypted: Vec<u8>) -> Result<Vec<u8>, Error> {
163
+ pub fn decrypt(&self, encrypted: Vec<u8>) -> Result<DecryptResult, Error> {
118
164
  match self.0.try_borrow_mut() {
119
165
  Ok(mut state) => {
120
166
  let mut buffer = BytesMut::new();
121
167
  buffer.extend_from_slice(&encrypted);
168
+ let result = state.decrypt(&mut buffer);
122
169
 
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
- }
170
+ Ok(DecryptResult::new(buffer.to_vec(), result))
138
171
  },
139
172
  Err(_e) => { Err(Error::new(get_ruby().get_inner(&BASE_ERROR), "borrow error")) }
140
173
  }
@@ -149,18 +182,23 @@ fn get_ruby() -> Ruby {
149
182
  #[magnus::init]
150
183
  fn init() -> Result<(), Error> {
151
184
  let module = define_module("RbMumbleProtocol")?;
152
- let class = module.define_class("CryptState", class::object())?;
185
+ let class1 = module.define_class("CryptState", class::object())?;
186
+
187
+ class1.define_singleton_method("new", function!(CryptStateRef::new, 0))?;
188
+ class1.define_singleton_method("new_from", function!(CryptStateRef::new_from, 3))?;
153
189
 
154
- class.define_singleton_method("new", function!(CryptStateRef::new, 0))?;
155
- class.define_singleton_method("new_from", function!(CryptStateRef::new_from, 3))?;
190
+ class1.define_method("key", method!(CryptStateRef::key, 0))?;
191
+ class1.define_method("encrypt_nonce", method!(CryptStateRef::encrypt_nonce, 0))?;
192
+ class1.define_method("decrypt_nonce", method!(CryptStateRef::decrypt_nonce, 0))?;
193
+ class1.define_method("stats", method!(CryptStateRef::stats, 0))?;
156
194
 
157
- class.define_method("key", method!(CryptStateRef::key, 0))?;
158
- class.define_method("encrypt_nonce", method!(CryptStateRef::encrypt_nonce, 0))?;
159
- class.define_method("decrypt_nonce", method!(CryptStateRef::decrypt_nonce, 0))?;
160
- class.define_method("stats", method!(CryptStateRef::stats, 0))?;
195
+ class1.define_method("encrypt", method!(CryptStateRef::encrypt, 1))?;
196
+ class1.define_method("decrypt", method!(CryptStateRef::decrypt, 1))?;
161
197
 
162
- class.define_method("encrypt", method!(CryptStateRef::encrypt, 1))?;
163
- class.define_method("decrypt", method!(CryptStateRef::decrypt, 1))?;
198
+ let class2 = module.define_class("DecryptResult", class::object())?;
199
+ class2.define_method("success?", method!(DecryptResult::is_success, 0))?;
200
+ class2.define_method("data", method!(DecryptResult::data, 0))?;
201
+ class2.define_method("reason_raw_value", method!(DecryptResult::reason_raw_value, 0))?;
164
202
 
165
203
  Ok(())
166
204
  }
@@ -1,9 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RbMumbleProtocol
4
- class Error < StandardError
4
+ class CryptState
5
5
  end
6
6
 
7
- class CryptState
7
+ class DecryptResult
8
+ REASONS = {
9
+ 0 => :ok,
10
+ 1 => :repeat,
11
+ 2 => :late,
12
+ 3 => :mac,
13
+ 4 => :eof
14
+ }.freeze
15
+
16
+ def reason
17
+ REASONS[reason_raw_value]
18
+ end
8
19
  end
9
20
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RbMumbleProtocol
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,15 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rb_mumble_protocol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.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: 2024-02-09 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-02-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.21'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.21'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
13
55
  description: Gem that providing classes for implementing Mumble-related projects.
14
56
  email:
15
57
  - derpiranha@gmail.com