Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5-internal/libzauth-dependency-upgrades
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Upgrade version of libzauth dependencies, notably sodiumoxide bindings to libsodium, and fix resulting errors and warnings.
125 changes: 100 additions & 25 deletions libs/libzauth/libzauth-c/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion libs/libzauth/libzauth-c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ uninstall:
rm -f $(PREFIX_INSTALL)/lib/libzauth.$(LIB_TYPE)
rm -f $(PREFIX_INSTALL)/lib/pkgconfig/libzauth.pc

dist: build-release
.PHONY: test
test:
cd ../libzauth && cargo test --release

dist: test build-release
mkdir -p deb$(PREFIX_PACKAGE)/include
mkdir -p deb$(PREFIX_PACKAGE)/lib/pkgconfig
cp src/zauth.h deb$(PREFIX_PACKAGE)/include/
Expand Down
17 changes: 7 additions & 10 deletions libs/libzauth/libzauth-c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
extern crate libc;
extern crate zauth;

use libc::{size_t, uint8_t};
use libc::size_t;
use std::char;
use std::fs::File;
use std::io::{self, BufReader, Read};
Expand All @@ -41,7 +41,6 @@ macro_rules! try_unwrap {
}

#[repr(C)]
#[no_mangle]
#[derive(Clone, Copy, Debug)]
pub struct Range {
ptr: *const u8,
Expand All @@ -53,7 +52,7 @@ pub struct ZauthKeystore(zauth::Keystore);
pub struct ZauthToken(zauth::Token<'static>);

#[no_mangle]
pub extern fn zauth_keystore_open(f: *const uint8_t, n: size_t, s: *mut *mut ZauthKeystore) -> ZauthResult {
pub extern fn zauth_keystore_open(f: *const u8, n: size_t, s: *mut *mut ZauthKeystore) -> ZauthResult {
if f.is_null() {
return ZauthResult::NullArg;
}
Expand All @@ -77,7 +76,7 @@ pub extern fn zauth_keystore_delete(s: *mut ZauthKeystore) {
}

#[no_mangle]
pub extern fn zauth_acl_open(f: *const uint8_t, n: size_t, a: *mut *mut ZauthAcl) -> ZauthResult {
pub extern fn zauth_acl_open(f: *const u8, n: size_t, a: *mut *mut ZauthAcl) -> ZauthResult {
if f.is_null() {
return ZauthResult::NullArg;
}
Expand All @@ -104,7 +103,7 @@ pub extern fn zauth_acl_delete(a: *mut ZauthAcl) {
}

#[no_mangle]
pub extern fn zauth_token_parse(cs: *const uint8_t, n: size_t, zt: *mut *mut ZauthToken) -> ZauthResult {
pub extern fn zauth_token_parse(cs: *const u8, n: size_t, zt: *mut *mut ZauthToken) -> ZauthResult {
if cs.is_null() {
return ZauthResult::NullArg;
}
Expand All @@ -129,7 +128,7 @@ pub extern fn zauth_token_verify(t: &ZauthToken, s: &ZauthKeystore) -> ZauthResu

#[no_mangle]
pub extern
fn zauth_token_allowed(t: &ZauthToken, acl: &ZauthAcl, cp: *const uint8_t, n: size_t, out: *mut uint8_t) -> ZauthResult {
fn zauth_token_allowed(t: &ZauthToken, acl: &ZauthAcl, cp: *const u8, n: size_t, out: *mut u8) -> ZauthResult {
catch_unwind(|| {
let b = unsafe { slice::from_raw_parts(cp, n) };
let s = try_unwrap!(str::from_utf8(b));
Expand All @@ -154,12 +153,12 @@ pub extern fn zauth_token_type(t: &ZauthToken) -> ZauthTokenType {
//}

#[no_mangle]
pub extern fn zauth_token_version(t: &ZauthToken) -> uint8_t {
pub extern fn zauth_token_version(t: &ZauthToken) -> u8 {
t.0.version
}

#[no_mangle]
pub extern fn zauth_token_lookup(t: &ZauthToken, c: uint8_t) -> Range {
pub extern fn zauth_token_lookup(t: &ZauthToken, c: u8) -> Range {
if let Some(k) = char::from_u32(c as u32) {
if let Some(s) = t.0.lookup(k) {
return Range { ptr: s.as_ptr(), len: s.len() }
Expand All @@ -177,7 +176,6 @@ pub extern fn zauth_token_delete(t: *mut ZauthToken) {
}

#[repr(C)]
#[no_mangle]
#[derive(Clone, Copy, Debug)]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@comawill this is the place I'm least sure about my change: the no_mangle at the enum level led to warnings; but I'm not sure if removing them is okay to do here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine. I don't think enum names or enum value names are part of the C ABI.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think no_mangle on structs and enums doesn't do anything, so it is safe to remove.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for your reviews!

pub enum ZauthTokenType {
User = 0,
Expand All @@ -204,7 +202,6 @@ impl From<TokenType> for ZauthTokenType {
}

#[repr(C)]
#[no_mangle]
#[derive(Clone, Copy, Debug)]
pub enum ZauthResult {
Ok = 0,
Expand Down
3 changes: 3 additions & 0 deletions libs/libzauth/libzauth/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# this file is not required to track in git as it is a library here and lock files are only used for binaries
# we track the lock file in libzauth-c.
Cargo.lock
2 changes: 1 addition & 1 deletion libs/libzauth/libzauth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name = "zauth"
[dependencies]
asexp = ">= 0.3"
rustc-serialize = ">= 0.3"
sodiumoxide = "= 0.0.16"
sodiumoxide = "^0.2.7"

[dev-dependencies]
clap = ">= 2.0"
12 changes: 6 additions & 6 deletions libs/libzauth/libzauth/examples/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@
extern crate clap;
extern crate zauth;

use clap::{Arg, App};
use clap::{Arg, Command};
use std::path::Path;
use std::process;
use zauth::{Token, Keystore};

pub fn main() {
let args = App::new("verify")
let args = Command::new("verify")
.about("Test application verifying tokens")
.arg(Arg::with_name("store")
.arg(Arg::new("store")
.required(true)
.short("s")
.short('s')
.long("store")
.value_name("FILE")
.help("Keystore")
.takes_value(true))
.arg(Arg::with_name("token")
.arg(Arg::new("token")
.required(true)
.short("t")
.short('t')
.long("token")
.value_name("STRING")
.help("Token string to verify")
Expand Down
6 changes: 3 additions & 3 deletions libs/libzauth/libzauth/src/acl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ impl Acl {
let mut acl = HashMap::new();
for &(ref key, ref list) in entries {
if let Some(k) = key.get_str().map(String::from) {
acl.insert(k, try!(List::from_sexp(&list)));
acl.insert(k, List::from_sexp(&list)?);
} else {
return Err(Error::Parse("not a string"))
}
}
Ok(Acl { acl: acl })
Ok(Acl { acl })
}
_ => Err(Error::Parse("expected key and values"))
}
Expand Down Expand Up @@ -104,7 +104,7 @@ impl List {
_ => {
let mut t = Tree::new();
for x in xs {
t.add(&try!(List::read_path(x)))
t.add(&List::read_path(x)?)
}
Ok(Some(t))
}
Expand Down
2 changes: 1 addition & 1 deletion libs/libzauth/libzauth/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl error::Error for Error {
"zauth error"
}

fn cause(&self) -> Option<&error::Error> {
fn cause(&self) -> Option<&dyn error::Error> {
match *self {
Error::Io(ref e) => Some(e),
_ => None
Expand Down
Loading