pub struct Token {
pub device: String,
pub expires_at: Option<i64>,
}Expand description
What is known about the token this installation holds.
Read out of the token itself rather than remembered separately. The server states the device name and the expiry when it issues it, and a second copy kept elsewhere is a second thing that can be wrong.
Fields§
§device: StringThe device name the server approved.
expires_at: Option<i64>When it stops being accepted, as seconds since the epoch. None
when the server issued it without an expiry.
Implementations§
Source§impl Token
impl Token
Sourcepub fn read(raw: &str) -> Option<Self>
pub fn read(raw: &str) -> Option<Self>
Reads what a Signal K device token says about itself.
The token is a JWT: three dot-separated parts, of which the middle one is base64url-encoded JSON. Only read here, never checked – the signature is over a secret only the server holds, so this cannot verify anything and does not pretend to. It is the server’s word, displayed as the server’s word.
Sourcepub fn expired(&self, now_unix: i64) -> bool
pub fn expired(&self, now_unix: i64) -> bool
Whether the server would still accept it, as far as the token says,
at now_unix (seconds since the epoch).
“As far as the token says” is the whole caveat: a token can also stop working because the administrator removed the device, and nothing in the token itself shows that. Only the server can answer that, by refusing.
now_unix is a parameter rather than read from the system clock
here, the same reason every other time-sensitive answer in this
workspace takes now in: a caller replaying a recorded run gets the
identical answer a live one would have.