Skip to content

Commit a9b3d4f

Browse files
committed
fix: algorithm transformation & decode header fn
1 parent 4f7dd78 commit a9b3d4f

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

packages/jsonwebtoken/src/algorithm.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,26 @@ impl From<Algorithm> for jsonwebtoken::Algorithm {
4848
}
4949
}
5050

51+
impl From<jsonwebtoken::Algorithm> for Algorithm {
52+
#[inline]
53+
fn from(value: jsonwebtoken::Algorithm) -> Self {
54+
match value {
55+
jsonwebtoken::Algorithm::ES256 => Algorithm::ES256,
56+
jsonwebtoken::Algorithm::ES384 => Algorithm::ES384,
57+
jsonwebtoken::Algorithm::EdDSA => Algorithm::EdDSA,
58+
jsonwebtoken::Algorithm::HS256 => Algorithm::HS256,
59+
jsonwebtoken::Algorithm::HS384 => Algorithm::HS384,
60+
jsonwebtoken::Algorithm::HS512 => Algorithm::HS512,
61+
jsonwebtoken::Algorithm::PS256 => Algorithm::PS256,
62+
jsonwebtoken::Algorithm::PS384 => Algorithm::PS384,
63+
jsonwebtoken::Algorithm::PS512 => Algorithm::PS512,
64+
jsonwebtoken::Algorithm::RS256 => Algorithm::RS256,
65+
jsonwebtoken::Algorithm::RS384 => Algorithm::RS384,
66+
jsonwebtoken::Algorithm::RS512 => Algorithm::RS512,
67+
}
68+
}
69+
}
70+
5171
impl Default for Algorithm {
5272
fn default() -> Self {
5373
Self::HS256

packages/jsonwebtoken/src/decode.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ use napi_derive::napi;
33
use crate::header::Header;
44

55
#[napi]
6-
pub fn decode_header(token: &str) -> Header {
6+
pub fn decode_header(token: String) -> Header {
77
let result = jsonwebtoken::decode_header(&token);
88

9-
let header = Header::from(result.unwrap());
9+
let header = result.unwrap().into();
10+
return header;
1011
}

packages/jsonwebtoken/src/header.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ impl From<&Header> for jsonwebtoken::Header {
7373
}
7474
}
7575

76-
impl From<&jsonwebtoken::Header> for Header {
76+
impl From<jsonwebtoken::Header> for Header {
7777
#[inline]
78-
fn from(value: &jsonwebtoken::Header) -> Header {
78+
fn from(value: jsonwebtoken::Header) -> Header {
7979
Header {
80-
algorithm: value.alg.clone(),
80+
algorithm: Algorithm::from(value.alg.clone()).into(),
8181
content_type: value.cty.clone(),
8282
json_key_url: value.jku.clone(),
8383
key_id: value.kid.clone(),

0 commit comments

Comments
 (0)