about summary refs log tree commit diff
path: root/kittybox-rs
diff options
context:
space:
mode:
Diffstat (limited to 'kittybox-rs')
-rw-r--r--kittybox-rs/indieauth/src/lib.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/kittybox-rs/indieauth/src/lib.rs b/kittybox-rs/indieauth/src/lib.rs
index 242317d..3575132 100644
--- a/kittybox-rs/indieauth/src/lib.rs
+++ b/kittybox-rs/indieauth/src/lib.rs
@@ -197,6 +197,10 @@ impl TokenData {
     }
 }
 
+// I don't like this type, because it could've been represented
+// internally by Option<TokenData>. But the IndieAuth standard
+// requires the "active" field to be present. I can't do anything
+// about it.
 #[derive(Debug, Serialize, Deserialize)]
 pub struct TokenIntrospectionResponse {
     active: bool,
@@ -204,6 +208,8 @@ pub struct TokenIntrospectionResponse {
     #[serde(skip_serializing_if = "Option::is_none")]
     data: Option<TokenData>
 }
+// These wrappers and impls should take care of making use of this
+// type as painless as possible.
 impl TokenIntrospectionResponse {
     pub fn inactive() -> Self {
         Self { active: false, data: None }
@@ -228,6 +234,16 @@ impl Default for TokenIntrospectionResponse {
         Self::inactive()
     }
 }
+impl From<Option<TokenData>> for TokenIntrospectionResponse {
+    fn from(data: Option<TokenData>) -> Self {
+        Self { active: data.is_some(), data }
+    }
+}
+impl From<TokenIntrospectionResponse> for Option<TokenData> {
+    fn from(response: TokenIntrospectionResponse) -> Option<TokenData> {
+        response.data
+    }
+}
 
 #[derive(Debug, Serialize, Deserialize)]
 pub struct TokenRevocationRequest {