I have no idea why this is not working. My tests pass the earlier expiry stage, but when reading the expiry from the rdb file the same code is failing. Can anyone suggest how to fix this?
The expiry values in $yz1 are read from command line and are supplied as values in milliseconds. Those value are exactly as passed in, with the “px” option. The values in #sm4 are timestamp values and thats where I’m not sure my parsing is correct
Thanks so much for your help. Still haven’t fixed it and I’m guessing it must be something simple. I converted the “px” values to timestamps with this function:
fn to_timestamp(expiry: u128) -> u128 {
let exp_timestamp = SystemTime::now() + Duration::from_millis(expiry as u64);
exp_timestamp.duration_since(UNIX_EPOCH).unwrap().as_millis() as u128
}
and my function to check expiry is this:
pub fn is_key_expired(expiry: u128) -> bool {
let current_time = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as u128;
current_time >= expiry
}
I grabbed that expiry value and converted it with an online tool. I can confirm it is indeed expired. The date it represents is Saturday January 1, 2022.
Feel free to use this snippet to print out the hex dump:
Click me
// Open the file
let mut file = File::open(&path)?;
let mut buffer = Vec::new();
// Read the file content into the buffer
file.read_to_end(&mut buffer)?;
// Process the file buffer to mimic `xxd` output with extra newlines for readability
for (i, chunk) in buffer.chunks(16).enumerate() {
// Print the offset at the beginning of each line
print!("{:08x}: ", i * 16);
// Print hex values for each byte in the chunk
for byte in chunk {
print!("{:02x} ", byte);
}
// Pad hex column if the last chunk is less than 16 bytes
if chunk.len() < 16 {
for _ in 0..(16 - chunk.len()) {
print!(" ");
}
}
// Print ASCII representation for each byte in the chunk
print!("|");
for byte in chunk {
let ch = if *byte == 0x0c || !byte.is_ascii_graphic() {
'.'
} else {
*byte as char
};
print!("{}", ch);
}
print!("|\n"); // Newline after each chunk for readability
}