Skip to content

Commit d1fcd1f

Browse files
committed
Prepare for crates
See CHANGELOG as there may be breaking changes with this Update. Closes #71
1 parent a6383f2 commit d1fcd1f

File tree

4 files changed

+246
-140
lines changed

4 files changed

+246
-140
lines changed

rust/vapid/CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# 0.2.0
2+
3+
Due to changes in the OpenSSL library, several calls changed form from `0.1.0`
4+
5+
Most calls now return as a `Result<_, VapidError>`. `VapidError` is a type of `failure` call, so it should make logging and error handling a bit easier.
6+
7+
This does mean that
8+
9+
```rust, no_run
10+
let key = Key::generate();
11+
```
12+
is now
13+
```rust, no_run
14+
let key = Key.generate().unwrap();
15+
```
16+
17+
The `.group()` method for `Key` has been removed. It was a convenience function. You can replace it with generating the group directly
18+
`ec::EcGroup::from_curve_name(nid::Nid::X9_62_PRIME256V1)?`
19+
20+
There are now `VapidErrors`

rust/vapid/Cargo.toml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
[package]
22
name = "vapid"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
authors = ["jrconlin <[email protected]>"]
5+
edition = "2018"
6+
description = "An implementation of the RFC 8292 Voluntary Application Server Identification (VAPID) Auth header generator"
7+
repository = "https://github.com/web-push-libs/vapid"
8+
license = "MPL 2.0"
59

610
[dependencies]
7-
openssl = "0.9.16"
8-
serde_json = "1.0.2"
9-
base64 = "0.6.0"
11+
openssl = "0.10"
12+
serde_json = "1.0"
13+
base64 = "0.10"
1014
time = "0.1"
15+
failure = "0.1"

rust/vapid/src/error.rs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Error handling based on the failure crate
2+
3+
use std::fmt;
4+
use std::result;
5+
6+
use failure::{Backtrace, Context, Error, Fail};
7+
8+
pub type VapidResult<T> = result::Result<T, Error>;
9+
10+
#[derive(Debug)]
11+
pub struct VapidError {
12+
inner: Context<VapidErrorKind>,
13+
}
14+
15+
#[derive(Clone, Eq, PartialEq, Debug, Fail)]
16+
pub enum VapidErrorKind {
17+
#[fail(display = "Invalid public key")]
18+
PublicKeyError,
19+
#[fail(display = "VAPID error: {}", _0)]
20+
VapidError(String),
21+
#[fail(display = "Internal Error {:?}", _0)]
22+
InternalError(String),
23+
}
24+
25+
/*
26+
impl VapidError {
27+
pub fn kind(&self) -> &VapidErrorKind {
28+
self.inner.get_context()
29+
}
30+
}
31+
*/
32+
33+
impl Fail for VapidError {
34+
fn cause(&self) -> Option<&Fail> {
35+
self.inner.cause()
36+
}
37+
38+
fn backtrace(&self) -> Option<&Backtrace> {
39+
self.inner.backtrace()
40+
}
41+
}
42+
43+
impl fmt::Display for VapidError {
44+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
45+
fmt::Display::fmt(&self.inner, f)
46+
}
47+
}
48+
49+
impl From<VapidErrorKind> for VapidError {
50+
fn from(kind: VapidErrorKind) -> VapidError {
51+
Context::new(kind).into()
52+
}
53+
}
54+
55+
impl From<Context<VapidErrorKind>> for VapidError {
56+
fn from(inner: Context<VapidErrorKind>) -> VapidError {
57+
VapidError { inner }
58+
}
59+
}
60+
61+
impl From<Error> for VapidError {
62+
fn from(err: Error) -> VapidError {
63+
VapidErrorKind::InternalError(format!("Error: {:?}", err)).into()
64+
}
65+
}

0 commit comments

Comments
 (0)