Skip to content

Commit 6edd4f7

Browse files
authored
Merge pull request #19 from mathstuf/add-cirrus-ci
Add cirrus ci
2 parents 186f7c4 + c13ab42 commit 6edd4f7

File tree

13 files changed

+210
-65
lines changed

13 files changed

+210
-65
lines changed

.cirrus.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
clippy_task:
2+
container:
3+
image: rustlang/rust:nightly
4+
keyutils_script: apt-get update && apt-get install libkeyutils-dev
5+
component_script: rustup component add clippy
6+
update_script: cargo +nightly update
7+
toolchain_cache:
8+
folder: $RUSTUP_HOME
9+
fingerprint_script: rustc +nightly --version
10+
cargo_cache:
11+
folder: $CARGO_HOME/registry
12+
fingerprint_script: cat Cargo.lock
13+
fmt_script: cargo +nightly clippy
14+
15+
rustfmt_task:
16+
container:
17+
image: rustlang/rust:nightly
18+
keyutils_script: apt-get update && apt-get install libkeyutils-dev
19+
component_script: rustup component add rustfmt
20+
fmt_script: cargo fmt --all -- --check
21+
22+
linux_task:
23+
container:
24+
image: rust:latest
25+
matrix:
26+
- env:
27+
RUSTVER: 1.32.0
28+
- env:
29+
RUSTVER: stable
30+
- allow_failures: true
31+
env:
32+
RUSTVER: nightly
33+
keyutils_script: apt-get update && apt-get install libkeyutils-dev
34+
rustup_script: rustup toolchain install $RUSTVER
35+
toolchain_cache:
36+
folder: $RUSTUP_HOME
37+
fingerprint_script: rustc +$RUSTVER --version
38+
update_script: cargo +$RUSTVER update
39+
cargo_cache:
40+
folder: $CARGO_HOME/registry
41+
fingerprint_script: cat Cargo.lock
42+
build_script: cargo +$RUSTVER build
43+
test_script: cargo +$RUSTVER test
44+
before_cache_script: rm -rf $CARGO_HOME/registry/index
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
match_block_trailing_comma = true
21
force_multiline_blocks = true
3-
report_todo = "Unnumbered"
2+
license_template_path = ".license.template"
3+
match_block_trailing_comma = true
44
report_fixme = "Unnumbered"
5+
report_todo = "Unnumbered"
56
struct_lit_single_line = false
6-
license_template_path = ".license.template"

libkeyutils-sys/src/constants.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
use types::{key_perm_t, key_serial_t};
3131

32-
pub const KEY_TYPE_USER: &'static str = "user";
33-
pub const KEY_TYPE_LOGON: &'static str = "logon";
32+
pub const KEY_TYPE_USER: &str = "user";
33+
pub const KEY_TYPE_LOGON: &str = "logon";
3434

3535
pub const KEY_SPEC_THREAD_KEYRING: key_serial_t = -1;
3636
pub const KEY_SPEC_PROCESS_KEYRING: key_serial_t = -2;
@@ -49,34 +49,34 @@ pub const KEY_REQKEY_DEFL_USER_KEYRING: key_serial_t = 4;
4949
pub const KEY_REQKEY_DEFL_USER_SESSION_KEYRING: key_serial_t = 5;
5050
pub const KEY_REQKEY_DEFL_GROUP_KEYRING: key_serial_t = 6;
5151

52-
pub const KEY_POS_VIEW: key_perm_t = 0x01000000; /* possessor can view a key's attributes */
53-
pub const KEY_POS_READ: key_perm_t = 0x02000000; /* possessor can read key payload / view keyring */
54-
pub const KEY_POS_WRITE: key_perm_t = 0x04000000; /* possessor can update key payload / add link to keyring */
55-
pub const KEY_POS_SEARCH: key_perm_t = 0x08000000; /* possessor can find a key in search / search a keyring */
56-
pub const KEY_POS_LINK: key_perm_t = 0x10000000; /* possessor can create a link to a key/keyring */
57-
pub const KEY_POS_SETATTR: key_perm_t = 0x20000000; /* possessor can set key attributes */
58-
pub const KEY_POS_ALL: key_perm_t = 0x3f000000;
52+
pub const KEY_POS_VIEW: key_perm_t = 0x0100_0000; /* possessor can view a key's attributes */
53+
pub const KEY_POS_READ: key_perm_t = 0x0200_0000; /* possessor can read key payload / view keyring */
54+
pub const KEY_POS_WRITE: key_perm_t = 0x0400_0000; /* possessor can update key payload / add link to keyring */
55+
pub const KEY_POS_SEARCH: key_perm_t = 0x0800_0000; /* possessor can find a key in search / search a keyring */
56+
pub const KEY_POS_LINK: key_perm_t = 0x1000_0000; /* possessor can create a link to a key/keyring */
57+
pub const KEY_POS_SETATTR: key_perm_t = 0x2000_0000; /* possessor can set key attributes */
58+
pub const KEY_POS_ALL: key_perm_t = 0x3f00_0000;
5959

60-
pub const KEY_USR_VIEW: key_perm_t = 0x00010000; /* user permissions... */
61-
pub const KEY_USR_READ: key_perm_t = 0x00020000;
62-
pub const KEY_USR_WRITE: key_perm_t = 0x00040000;
63-
pub const KEY_USR_SEARCH: key_perm_t = 0x00080000;
64-
pub const KEY_USR_LINK: key_perm_t = 0x00100000;
65-
pub const KEY_USR_SETATTR: key_perm_t = 0x00200000;
66-
pub const KEY_USR_ALL: key_perm_t = 0x003f0000;
60+
pub const KEY_USR_VIEW: key_perm_t = 0x0001_0000; /* user permissions... */
61+
pub const KEY_USR_READ: key_perm_t = 0x0002_0000;
62+
pub const KEY_USR_WRITE: key_perm_t = 0x0004_0000;
63+
pub const KEY_USR_SEARCH: key_perm_t = 0x0008_0000;
64+
pub const KEY_USR_LINK: key_perm_t = 0x0010_0000;
65+
pub const KEY_USR_SETATTR: key_perm_t = 0x0020_0000;
66+
pub const KEY_USR_ALL: key_perm_t = 0x003f_0000;
6767

68-
pub const KEY_GRP_VIEW: key_perm_t = 0x00000100; /* group permissions... */
69-
pub const KEY_GRP_READ: key_perm_t = 0x00000200;
70-
pub const KEY_GRP_WRITE: key_perm_t = 0x00000400;
71-
pub const KEY_GRP_SEARCH: key_perm_t = 0x00000800;
72-
pub const KEY_GRP_LINK: key_perm_t = 0x00001000;
73-
pub const KEY_GRP_SETATTR: key_perm_t = 0x00002000;
74-
pub const KEY_GRP_ALL: key_perm_t = 0x00003f00;
68+
pub const KEY_GRP_VIEW: key_perm_t = 0x0000_0100; /* group permissions... */
69+
pub const KEY_GRP_READ: key_perm_t = 0x0000_0200;
70+
pub const KEY_GRP_WRITE: key_perm_t = 0x0000_0400;
71+
pub const KEY_GRP_SEARCH: key_perm_t = 0x0000_0800;
72+
pub const KEY_GRP_LINK: key_perm_t = 0x0000_1000;
73+
pub const KEY_GRP_SETATTR: key_perm_t = 0x0000_2000;
74+
pub const KEY_GRP_ALL: key_perm_t = 0x0000_3f00;
7575

76-
pub const KEY_OTH_VIEW: key_perm_t = 0x00000001; /* third party permissions... */
77-
pub const KEY_OTH_READ: key_perm_t = 0x00000002;
78-
pub const KEY_OTH_WRITE: key_perm_t = 0x00000004;
79-
pub const KEY_OTH_SEARCH: key_perm_t = 0x00000008;
80-
pub const KEY_OTH_LINK: key_perm_t = 0x00000010;
81-
pub const KEY_OTH_SETATTR: key_perm_t = 0x00000020;
82-
pub const KEY_OTH_ALL: key_perm_t = 0x0000003f;
76+
pub const KEY_OTH_VIEW: key_perm_t = 0x0000_0001; /* third party permissions... */
77+
pub const KEY_OTH_READ: key_perm_t = 0x0000_0002;
78+
pub const KEY_OTH_WRITE: key_perm_t = 0x0000_0004;
79+
pub const KEY_OTH_SEARCH: key_perm_t = 0x0000_0008;
80+
pub const KEY_OTH_LINK: key_perm_t = 0x0000_0010;
81+
pub const KEY_OTH_SETATTR: key_perm_t = 0x0000_0020;
82+
pub const KEY_OTH_ALL: key_perm_t = 0x0000_003f;

libkeyutils-sys/src/functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crates::libc;
2828

2929
use types::{key_perm_t, key_serial_t};
3030

31-
#[cfg_attr(rustfmt, rustfmt_skip)]
31+
#[rustfmt::skip]
3232
extern "C" {
3333
pub fn add_key(
3434
type_: *const libc::c_char,

src/api.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,6 @@
2424
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
2525
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626

27-
use crates::errno;
28-
use crates::libc;
29-
use crates::libkeyutils_sys::*;
30-
31-
use constants::{DefaultKeyring, KeyringSerial, KeyPermissions, Permission, SpecialKeyring};
32-
use keytype::*;
33-
use keytypes;
34-
3527
use std::borrow::Borrow;
3628
use std::ffi::CString;
3729
use std::mem;
@@ -40,6 +32,14 @@ use std::result;
4032
use std::str;
4133
use std::time::Duration;
4234

35+
use crates::errno;
36+
use crates::libc;
37+
use crates::libkeyutils_sys::*;
38+
39+
use constants::{DefaultKeyring, KeyPermissions, KeyringSerial, Permission, SpecialKeyring};
40+
use keytype::*;
41+
use keytypes;
42+
4343
/// Reexport of `Errno` as `Error`.
4444
pub type Error = errno::Errno;
4545
/// Simpler `Result` type with the error already set.
@@ -81,13 +81,13 @@ impl Keyring {
8181
/// This is unsafe because no keyring is known to exist with the given ID.
8282
pub unsafe fn new(id: KeyringSerial) -> Self {
8383
Keyring {
84-
id: id,
84+
id,
8585
}
8686
}
8787

8888
fn new_impl(id: KeyringSerial) -> Self {
8989
Keyring {
90-
id: id,
90+
id,
9191
}
9292
}
9393

@@ -512,7 +512,7 @@ impl Key {
512512

513513
fn new_impl(id: KeyringSerial) -> Self {
514514
Key {
515-
id: id,
515+
id,
516516
}
517517
}
518518

@@ -730,7 +730,7 @@ pub struct KeyManager {
730730
impl KeyManager {
731731
fn new(key: Key) -> Self {
732732
KeyManager {
733-
key: key,
733+
key,
734734
}
735735
}
736736

@@ -805,11 +805,11 @@ impl KeyManager {
805805

806806
#[cfg(test)]
807807
mod tests {
808-
use crates::libc;
809-
810808
use std::thread;
811809
use std::time::Duration;
812810

811+
use crates::libc;
812+
813813
use api::Keyring;
814814
use constants::{Permission, SpecialKeyring};
815815
use keytype::KeyType;

src/keytype.rs

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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 std::borrow::Cow;
28+
29+
/// A trait for representing a type of key in the Linux keyring subsystem.
30+
pub trait KeyType {
31+
/// The type for describing the key.
32+
type Description: KeyDescription + ?Sized;
33+
/// The type for representing a payload for the key.
34+
type Payload: KeyPayload + ?Sized;
35+
36+
/// The name of the keytype.
37+
fn name() -> &'static str;
38+
}
39+
40+
/// A description for a key.
41+
pub trait KeyDescription {
42+
/// The description of the key.
43+
fn description(&self) -> Cow<str>;
44+
}
45+
46+
impl KeyDescription for str {
47+
fn description(&self) -> Cow<str> {
48+
Cow::Borrowed(&self)
49+
}
50+
}
51+
52+
impl KeyDescription for String {
53+
fn description(&self) -> Cow<str> {
54+
Cow::Borrowed(&self)
55+
}
56+
}
57+
58+
/// A payload for a key.
59+
pub trait KeyPayload {
60+
/// The payload for the key.
61+
fn payload(&self) -> Cow<[u8]>;
62+
}
63+
64+
impl KeyPayload for () {
65+
fn payload(&self) -> Cow<[u8]> {
66+
Cow::Borrowed(&[])
67+
}
68+
}
69+
70+
impl KeyPayload for str {
71+
fn payload(&self) -> Cow<[u8]> {
72+
Cow::Borrowed(self.as_bytes())
73+
}
74+
}
75+
76+
impl KeyPayload for String {
77+
fn payload(&self) -> Cow<[u8]> {
78+
Cow::Borrowed(self.as_bytes())
79+
}
80+
}
81+
82+
impl KeyPayload for [u8] {
83+
fn payload(&self) -> Cow<[u8]> {
84+
Cow::Borrowed(self)
85+
}
86+
}
87+
88+
impl KeyPayload for Vec<u8> {
89+
fn payload(&self) -> Cow<[u8]> {
90+
Cow::Borrowed(&self)
91+
}
92+
}

src/keytypes/blacklist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626

2727
//! Certificate blacklist keys
2828
29+
use std::borrow::Cow;
30+
2931
use keytype::*;
3032
use keytypes::AsciiHex;
3133

32-
use std::borrow::Cow;
33-
3434
/// Blacklist hashes.
3535
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
3636
pub struct Blacklist;

src/keytypes/dns_resolver.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626

2727
//! DNS resolution keys
2828
29-
use keytype::*;
30-
3129
use std::borrow::Cow;
3230

31+
use keytype::*;
32+
3333
/// A DNS resolver key.
3434
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
3535
pub struct DnsResolver;

src/keytypes/encrypted.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626

2727
//! Encrypted keys
2828
29+
use std::borrow::Cow;
30+
2931
use keytype::*;
3032
use keytypes::AsciiHex;
3133

32-
use std::borrow::Cow;
33-
3434
/// Encrypted keys.
3535
///
3636
/// Encrypted keys are very similar to `Trusted` keys, however they do not require a TPM to

src/keytypes/logon.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
//!
2929
//! Logon keys are arbitrary keys that userspace cannot read once set.
3030
31+
use std::borrow::Cow;
32+
3133
use crates::libkeyutils_sys::KEY_TYPE_LOGON;
3234

3335
use keytype::*;
3436

35-
use std::borrow::Cow;
36-
3737
/// Keys which can only be created and updated from userspace but not read back.
3838
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
3939
pub struct Logon;

0 commit comments

Comments
 (0)