kopia lustrzana https://github.com/snarfed/bridgy-fed
move base64_to_long, long_to_base64 to common
rodzic
3cba0e272b
commit
b7bebb4075
19
common.py
19
common.py
|
@ -1,6 +1,7 @@
|
|||
# coding=utf-8
|
||||
"""Misc common utilities.
|
||||
"""
|
||||
import base64
|
||||
import copy
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
@ -9,6 +10,7 @@ import threading
|
|||
import urllib.parse
|
||||
|
||||
import cachetools
|
||||
from Crypto.Util import number
|
||||
from flask import abort, g, make_response, request
|
||||
from granary import as1, as2, microformats2
|
||||
import mf2util
|
||||
|
@ -48,6 +50,23 @@ DOMAIN_BLOCKLIST = frozenset((
|
|||
CACHE_TIME = timedelta(seconds=60)
|
||||
|
||||
|
||||
def base64_to_long(x):
|
||||
"""Converts x from URL safe base64 encoding to a long integer.
|
||||
|
||||
Originally from django_salmon.magicsigs. Used in :meth:`User.public_pem`
|
||||
and :meth:`User.private_pem`.
|
||||
"""
|
||||
return number.bytes_to_long(base64.urlsafe_b64decode(x))
|
||||
|
||||
|
||||
def long_to_base64(x):
|
||||
"""Converts x from a long integer to base64 URL safe encoding.
|
||||
|
||||
Originally from django_salmon.magicsigs. Used in :meth:`User.get_or_create`.
|
||||
"""
|
||||
return base64.urlsafe_b64encode(number.long_to_bytes(x))
|
||||
|
||||
|
||||
def host_url(path_query=None):
|
||||
base = request.host_url
|
||||
if (util.domain_or_parent_in(request.host, OTHER_DOMAINS) or
|
||||
|
|
19
models.py
19
models.py
|
@ -1,5 +1,4 @@
|
|||
"""Datastore model classes."""
|
||||
import base64
|
||||
from datetime import timedelta, timezone
|
||||
import itertools
|
||||
import json
|
||||
|
@ -10,7 +9,6 @@ import urllib.parse
|
|||
from arroba.mst import dag_cbor_cid
|
||||
from Crypto import Random
|
||||
from Crypto.PublicKey import ECC, RSA
|
||||
from Crypto.Util import number
|
||||
import dag_json
|
||||
from flask import g, request
|
||||
from google.cloud import ndb
|
||||
|
@ -23,6 +21,7 @@ from oauth_dropins.webutil.util import json_dumps, json_loads
|
|||
import requests
|
||||
|
||||
import common
|
||||
from common import base64_to_long, long_to_base64
|
||||
|
||||
# maps string label to Protocol subclass. populated by ProtocolUserMeta.
|
||||
# seed with old and upcoming protocols that don't have their own classes (yet).
|
||||
|
@ -65,22 +64,6 @@ def reset_protocol_properties():
|
|||
'source_protocol', choices=list(PROTOCOLS.keys()))
|
||||
|
||||
|
||||
def base64_to_long(x):
|
||||
"""Converts x from URL safe base64 encoding to a long integer.
|
||||
|
||||
Originally from django_salmon.magicsigs.
|
||||
"""
|
||||
return number.bytes_to_long(base64.urlsafe_b64decode(x))
|
||||
|
||||
|
||||
def long_to_base64(x):
|
||||
"""Converts x from a long integer to base64 URL safe encoding.
|
||||
|
||||
Originally from django_salmon.magicsigs.
|
||||
"""
|
||||
return base64.urlsafe_b64encode(number.long_to_bytes(x))
|
||||
|
||||
|
||||
class User(StringIdModel, metaclass=ProtocolUserMeta):
|
||||
"""Abstract base class for a Bridgy Fed user.
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue