Skip to content

Commit 8dcb202

Browse files
authored
Merge pull request #72 from web-push-libs/crates
Prepare for crates
2 parents a6383f2 + 20eaffc commit 8dcb202

File tree

4 files changed

+238
-146
lines changed

4 files changed

+238
-146
lines changed

rust/vapid/CHANGELOG.md

+20
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

+9-4
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

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
impl Fail for VapidError {
26+
fn cause(&self) -> Option<&Fail> {
27+
self.inner.cause()
28+
}
29+
30+
fn backtrace(&self) -> Option<&Backtrace> {
31+
self.inner.backtrace()
32+
}
33+
}
34+
35+
impl fmt::Display for VapidError {
36+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
37+
fmt::Display::fmt(&self.inner, f)
38+
}
39+
}
40+
41+
impl From<VapidErrorKind> for VapidError {
42+
fn from(kind: VapidErrorKind) -> VapidError {
43+
Context::new(kind).into()
44+
}
45+
}
46+
47+
impl From<Context<VapidErrorKind>> for VapidError {
48+
fn from(inner: Context<VapidErrorKind>) -> VapidError {
49+
VapidError { inner }
50+
}
51+
}
52+
53+
impl From<Error> for VapidError {
54+
fn from(err: Error) -> VapidError {
55+
VapidErrorKind::InternalError(format!("Error: {:?}", err)).into()
56+
}
57+
}

0 commit comments

Comments
 (0)