[fix] VerNum
This commit is contained in:
parent
68cedff1d9
commit
0827882bb3
30 changed files with 1651 additions and 240 deletions
|
|
@ -1,6 +1,52 @@
|
|||
use crate::terms_getter::Type;
|
||||
use iota_util::crypto_helper::hex_hash;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct LegalDocument {
|
||||
kind: Type,
|
||||
content: String,
|
||||
hash: String,
|
||||
version: String,
|
||||
timestamp: u64,
|
||||
}
|
||||
|
||||
impl LegalDocument {
|
||||
pub fn from_raw(kind: Type, content: String, timestamp: u64) -> Self {
|
||||
Self {
|
||||
kind,
|
||||
hash: hex_hash(&content),
|
||||
content,
|
||||
version: timestamp.to_string(),
|
||||
timestamp,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn metadata(&self) -> Doc {
|
||||
Doc::new(
|
||||
self.version.clone(),
|
||||
self.hash.clone(),
|
||||
self.kind,
|
||||
self.timestamp,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn kind(&self) -> Type {
|
||||
self.kind
|
||||
}
|
||||
|
||||
pub fn content(&self) -> &str {
|
||||
&self.content
|
||||
}
|
||||
|
||||
pub fn hash(&self) -> &str {
|
||||
&self.hash
|
||||
}
|
||||
|
||||
pub fn version(&self) -> &str {
|
||||
&self.version
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[allow(unused)]
|
||||
pub struct Doc {
|
||||
|
|
@ -58,7 +104,7 @@ impl Doc {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::Doc;
|
||||
use super::{Doc, LegalDocument};
|
||||
use crate::terms_getter::Type;
|
||||
use iota_util::crypto_helper::hex_hash;
|
||||
|
||||
|
|
@ -73,6 +119,18 @@ mod tests {
|
|||
assert_eq!(document.get_hash(), hex_hash(&content));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legal_document_hash_is_derived_from_its_owned_content() {
|
||||
let content = "# Privacy Policy\n".to_owned();
|
||||
let document = LegalDocument::from_raw(Type::PP, content.clone(), 123);
|
||||
|
||||
assert_eq!(document.kind(), Type::PP);
|
||||
assert_eq!(document.content(), content);
|
||||
assert_eq!(document.hash(), hex_hash(document.content()));
|
||||
assert_eq!(document.version(), "123");
|
||||
assert_eq!(document.metadata().get_hash(), document.hash());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn matching_documents_ignore_the_fetch_timestamp() {
|
||||
let earlier = Doc::from_raw(Type::EULA, "# EULA\n".to_owned(), 123);
|
||||
|
|
|
|||
|
|
@ -10,4 +10,4 @@ pub use terms_getter::get_terms;
|
|||
|
||||
pub mod doc;
|
||||
|
||||
pub use doc::Doc;
|
||||
pub use doc::{Doc, LegalDocument};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::doc::Doc;
|
||||
use crate::doc::LegalDocument;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
|
|
@ -41,7 +41,7 @@ pub fn get_newest_link(terms_type: Type) -> String {
|
|||
get_link(terms_type)
|
||||
}
|
||||
|
||||
pub async fn get_current_docs() -> Option<(Doc, Doc, Doc)> {
|
||||
pub async fn get_current_docs() -> Option<(LegalDocument, LegalDocument, LegalDocument)> {
|
||||
let timestamp = SystemTime::now().duration_since(UNIX_EPOCH).ok()?.as_secs();
|
||||
let (eula, tos, privacy) = tokio::join!(
|
||||
get_terms(Type::EULA),
|
||||
|
|
@ -50,9 +50,9 @@ pub async fn get_current_docs() -> Option<(Doc, Doc, Doc)> {
|
|||
);
|
||||
|
||||
Some((
|
||||
Doc::from_raw(Type::EULA, eula?, timestamp),
|
||||
Doc::from_raw(Type::TOS, tos?, timestamp),
|
||||
Doc::from_raw(Type::PP, privacy?, timestamp),
|
||||
LegalDocument::from_raw(Type::EULA, eula?, timestamp),
|
||||
LegalDocument::from_raw(Type::TOS, tos?, timestamp),
|
||||
LegalDocument::from_raw(Type::PP, privacy?, timestamp),
|
||||
))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue