From e4c1514294443b9e6f6ed716dcad5ebec64c3af8 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Fri, 20 Jul 2018 14:32:54 -0700 Subject: prep for base32 encoded identifiers --- README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index 239e69a2..a17a3458 100644 --- a/README.md +++ b/README.md @@ -46,3 +46,25 @@ database/API (but is useful for paper lookups). - [ ] Authentication (eg, accounts, OAuth2, JWT) - [ ] Authorization (aka, roles) - [ ] bot vs. editor + +## Identifiers + +Fatcat entity identifiers are in "boring" + +Python helpers for conversion: + + import base64 + import uuid + + def fcid2uuid(s): + s = s.split('_')[-1].upper().encode('utf-8') + assert len(s) == 26 + raw = base64.b32decode(s + b"======") + return str(uuid.UUID(bytes=raw)).lower() + + def uuid2fcid(s): + raw = uuid.UUID(s).bytes + return base64.b32encode(raw)[:26].lower().decode('utf-8') + + test_uuid = '00000000-0000-0000-3333-000000000001' + assert test_uuid == fcid2uuid(uuid2fcid(test_uuid)) -- cgit v1.2.3