Skip to content

Commit 186f7c4

Browse files
committed
rxrpc: add rxrpc keytypes
1 parent 5cbdd59 commit 186f7c4

File tree

3 files changed

+154
-0
lines changed

3 files changed

+154
-0
lines changed

src/keytypes/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ pub use self::keyring::Keyring;
5252
pub mod logon;
5353
pub use self::logon::Logon;
5454

55+
pub mod rxrpc;
56+
pub use self::rxrpc::RxRPC;
57+
58+
pub mod rxrpc_s;
59+
pub use self::rxrpc_s::RxRPCServer;
60+
5561
pub mod trusted;
5662
pub use self::trusted::Trusted;
5763

src/keytypes/rxrpc.rs

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) 2015, Ben Boeckel
2+
// All rights reserved.
3+
//
4+
// Redistribution and use in source and binary forms, with or without modification,
5+
// are permitted provided that the following conditions are met:
6+
//
7+
// * Redistributions of source code must retain the above copyright notice,
8+
// this list of conditions and the following disclaimer.
9+
// * Redistributions in binary form must reproduce the above copyright notice,
10+
// this list of conditions and the following disclaimer in the documentation
11+
// and/or other materials provided with the distribution.
12+
// * Neither the name of this project nor the names of its contributors
13+
// may be used to endorse or promote products derived from this software
14+
// without specific prior written permission.
15+
//
16+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23+
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
use keytype::*;
28+
29+
use std::borrow::Cow;
30+
31+
/// An RxRPC client key.
32+
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
33+
pub struct RxRPC;
34+
35+
impl KeyType for RxRPC {
36+
/// RxRPC client key descriptions are free-form.
37+
type Description = str;
38+
type Payload = Payload;
39+
40+
fn name() -> &'static str {
41+
"rxrpc"
42+
}
43+
}
44+
45+
#[derive(Debug, Clone, PartialEq, Eq)]
46+
pub struct Payload {
47+
expiry: u32,
48+
version: u8,
49+
session_key: [u8; 8],
50+
ticket: Vec<u8>,
51+
}
52+
53+
impl KeyPayload for Payload {
54+
fn payload(&self) -> Cow<[u8]> {
55+
let mut payload = Vec::new();
56+
57+
// struct rxrpc_key_sec2_v1 {
58+
// uint16_t security_index; /* 2 */
59+
// uint16_t ticket_length; /* length of ticket[] */
60+
// uint32_t expiry; /* time at which expires */
61+
// uint8_t kvno; /* key version number */
62+
// uint8_t __pad[3];
63+
// uint8_t session_key[8]; /* DES session key */
64+
// uint8_t ticket[0]; /* the encrypted ticket */
65+
// };
66+
67+
payload.extend((2 as u16).to_ne_bytes().iter());
68+
payload.extend((self.ticket.len() as u16).to_ne_bytes().iter());
69+
payload.extend(self.expiry.to_ne_bytes().iter());
70+
payload.extend(self.version.to_ne_bytes().iter());
71+
payload.extend([0u8; 3].iter());
72+
payload.extend(self.session_key.iter());
73+
payload.extend(self.ticket.iter());
74+
75+
Cow::Owned(payload)
76+
}
77+
}

src/keytypes/rxrpc_s.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// Copyright (c) 2015, Ben Boeckel
2+
// All rights reserved.
3+
//
4+
// Redistribution and use in source and binary forms, with or without modification,
5+
// are permitted provided that the following conditions are met:
6+
//
7+
// * Redistributions of source code must retain the above copyright notice,
8+
// this list of conditions and the following disclaimer.
9+
// * Redistributions in binary form must reproduce the above copyright notice,
10+
// this list of conditions and the following disclaimer in the documentation
11+
// and/or other materials provided with the distribution.
12+
// * Neither the name of this project nor the names of its contributors
13+
// may be used to endorse or promote products derived from this software
14+
// without specific prior written permission.
15+
//
16+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
23+
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
//! RxRPC server keys
28+
29+
use keytype::*;
30+
31+
use std::borrow::Cow;
32+
33+
/// An RxRPC server key.
34+
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
35+
pub struct RxRPCServer;
36+
37+
impl KeyType for RxRPCServer {
38+
type Description = Description;
39+
type Payload = Payload;
40+
41+
fn name() -> &'static str {
42+
"rxrpc_s"
43+
}
44+
}
45+
46+
/// The description of an RxRPC server key.
47+
#[derive(Debug, Clone, PartialEq, Eq)]
48+
pub struct Description {
49+
/// The ID of the service.
50+
pub service_id: u16,
51+
/// The security index.
52+
pub security_index: u8,
53+
}
54+
55+
impl KeyDescription for Description {
56+
fn description(&self) -> Cow<str> {
57+
Cow::Owned(format!("{}:{}", self.service_id, self.security_index))
58+
}
59+
}
60+
61+
/// The payload for an RxRPC server key.
62+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
63+
pub struct Payload {
64+
key: [u8; 8],
65+
}
66+
67+
impl KeyPayload for Payload {
68+
fn payload(&self) -> Cow<[u8]> {
69+
Cow::Borrowed(&self.key)
70+
}
71+
}

0 commit comments

Comments
 (0)