2 Commits
0.1.0 ... 0.1.2

2 changed files with 2 additions and 9 deletions

View File

@@ -40,7 +40,7 @@ pub fn encrypt(data: String) -> String {
/// - `data` 待解密的内容 /// - `data` 待解密的内容
pub fn decrypt(data: String) -> Result<String, SpiralCipherError> { pub fn decrypt(data: String) -> Result<String, SpiralCipherError> {
if !data.starts_with("[") || data.len() <= 21 { if !data.starts_with("[") || data.len() <= 21 {
return Err(SpiralCipherError::CorruptedCipherData); return Ok(data);
} }
let data = data[1..].to_string(); let data = data[1..].to_string();
let key_seed = data[0..20].to_string(); let key_seed = data[0..20].to_string();

View File

@@ -69,13 +69,6 @@ impl HailSerialCodeAlgorithm {
current_time - *HAIL_PERIOD_START current_time - *HAIL_PERIOD_START
} }
/// 判断指定时间戳是否比已经存储的最后一次使用的时间戳要大。否则时间发生了回拨。
fn validate_timestamp(&self, timestamp: i64) -> bool {
let last_timestamp = self.last_timestamp.clone();
let last_timestamp = last_timestamp.lock().unwrap();
timestamp >= *last_timestamp
}
/// 生成一个64位长整型序列ID。 /// 生成一个64位长整型序列ID。
pub fn generate_serial(&self) -> i64 { pub fn generate_serial(&self) -> i64 {
let last_timestamp = self.last_timestamp.clone(); let last_timestamp = self.last_timestamp.clone();
@@ -93,7 +86,7 @@ impl HailSerialCodeAlgorithm {
std::thread::sleep(time::Duration::from_secs(1)); std::thread::sleep(time::Duration::from_secs(1));
continue; continue;
} }
} else if !self.validate_timestamp(timestamp) { } else if timestamp < *last_timestamp {
std::thread::sleep(time::Duration::from_secs(1)); std::thread::sleep(time::Duration::from_secs(1));
continue; continue;
} }