mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2025-07-27 06:14:29 +00:00
Add support for v2 attachment upload APIs
Upstream PR: https://github.com/bitwarden/server/pull/1229
This commit is contained in:
parent
7d5186e40a
commit
29ed82a359
4 changed files with 200 additions and 34 deletions
|
@ -3,6 +3,7 @@
|
|||
//
|
||||
use std::num::NonZeroU32;
|
||||
|
||||
use data_encoding::HEXLOWER;
|
||||
use ring::{digest, hmac, pbkdf2};
|
||||
|
||||
use crate::error::Error;
|
||||
|
@ -28,8 +29,6 @@ pub fn verify_password_hash(secret: &[u8], salt: &[u8], previous: &[u8], iterati
|
|||
// HMAC
|
||||
//
|
||||
pub fn hmac_sign(key: &str, data: &str) -> String {
|
||||
use data_encoding::HEXLOWER;
|
||||
|
||||
let key = hmac::Key::new(hmac::HMAC_SHA1_FOR_LEGACY_USE_ONLY, key.as_bytes());
|
||||
let signature = hmac::sign(&key, data.as_bytes());
|
||||
|
||||
|
@ -52,6 +51,10 @@ pub fn get_random(mut array: Vec<u8>) -> Vec<u8> {
|
|||
array
|
||||
}
|
||||
|
||||
pub fn generate_file_id() -> String {
|
||||
HEXLOWER.encode(&get_random(vec![0; 16])) // 128 bits
|
||||
}
|
||||
|
||||
pub fn generate_token(token_size: u32) -> Result<String, Error> {
|
||||
// A u64 can represent all whole numbers up to 19 digits long.
|
||||
if token_size > 19 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue