Skip to content

Commit 1232fd9

Browse files
committed
fix: handle error for ethereum session token id
1 parent fd2b259 commit 1232fd9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

adapter/src/ethereum.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ impl Adapter for EthereumAdapter {
185185
}
186186

187187
fn session_from_token(&self, token: &str) -> AdapterResult<Session> {
188+
if token.len() < 16 {
189+
return Err(AdapterError::Failed("invaild token id".to_string()));
190+
}
191+
188192
let token_id = token.to_owned()[token.len() - 16..].to_string();
189193

190194
let mut session_tokens = self.session_tokens.borrow_mut();
@@ -209,10 +213,8 @@ impl Adapter for EthereumAdapter {
209213
}
210214
};
211215

212-
let verified = match ewt_verify(header_encoded, payload_encoded, token_encoded) {
213-
Ok(v) => v,
214-
Err(e) => return Err(AdapterError::EwtVerifyFailed(e.to_string())),
215-
};
216+
let verified = ewt_verify(header_encoded, payload_encoded, token_encoded)
217+
.map_err(|e| map_error(&e.to_string()))?;
216218

217219
if self.whoami()? != verified.payload.id {
218220
return Err(AdapterError::Configuration(

0 commit comments

Comments
 (0)