cryptgeon/backend/src/note/model.rs

28 lines
592 B
Rust
Raw Normal View History

2021-05-01 12:39:40 +02:00
use bs62;
use ring::rand::SecureRandom;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone)]
pub struct Note {
2021-12-21 00:15:04 +01:00
pub meta: String,
2021-05-01 12:39:40 +02:00
pub contents: String,
2022-03-01 16:16:02 +01:00
pub views: Option<u32>,
2021-12-22 14:46:06 +01:00
pub expiration: Option<u32>,
2021-05-01 12:39:40 +02:00
}
#[derive(Serialize, Deserialize, Clone)]
2021-05-03 12:21:51 +02:00
pub struct NoteInfo {}
2021-05-01 12:39:40 +02:00
2021-05-02 03:07:08 +02:00
#[derive(Serialize, Deserialize, Clone)]
pub struct NotePublic {
2021-12-21 00:15:04 +01:00
pub meta: String,
2021-05-02 03:07:08 +02:00
pub contents: String,
}
2021-05-01 12:39:40 +02:00
pub fn generate_id() -> String {
2021-12-30 22:36:28 +01:00
let mut id: [u8; 32] = [0; 32];
2021-05-01 12:39:40 +02:00
let sr = ring::rand::SystemRandom::new();
let _ = sr.fill(&mut id);
return bs62::encode_data(&id);
}