Пример #1
0
def split_chunks(string, remarks):
    return json.loads(
        decode_str(
            rustcall(
                lib.semaphore_split_chunks,
                encode_str(string),
                encode_str(json.dumps(remarks)),
            )
        )
    )
Пример #2
0
 def verify(self, buf, sig, max_age=None):
     buf = make_buf(buf)
     sig = encode_str(sig)
     if max_age is None:
         return self._methodcall(lib.semaphore_publickey_verify, buf, sig)
     return self._methodcall(lib.semaphore_publickey_verify_timestamp, buf,
                             sig, max_age)
Пример #3
0
 def verify(self, buf, sig, max_age=None):
     buf = make_buf(buf)
     sig = encode_str(sig)
     if max_age is None:
         return self._methodcall(lib.semaphore_publickey_verify, buf, sig)
     return self._methodcall(
         lib.semaphore_publickey_verify_timestamp, buf, sig, max_age
     )
Пример #4
0
 def normalize_event(self, event=None, raw_event=None):
     if raw_event is None:
         raw_event = json.dumps(event, ensure_ascii=False).encode(
             "utf-8", errors="replace"
         )
     event = encode_str(raw_event, mutable=True)
     rustcall(lib.semaphore_translate_legacy_python_json, event)
     rv = self._methodcall(lib.semaphore_store_normalizer_normalize_event, event)
     return json.loads(decode_str(rv))
Пример #5
0
 def __new__(cls, geoip_lookup=None, **config):
     config = json.dumps(config)
     geoptr = geoip_lookup._get_objptr() if geoip_lookup is not None else ffi.NULL
     rv = cls._from_objptr(
         rustcall(lib.semaphore_store_normalizer_new, encode_str(config), geoptr)
     )
     if geoip_lookup is not None:
         attached_refs[rv] = geoip_lookup
     return rv
Пример #6
0
def create_register_challenge(data, signature, max_age=60 * 15):
    rv = json.loads(
        decode_str(
            rustcall(lib.semaphore_create_register_challenge, make_buf(data),
                     encode_str(signature), max_age)))
    return {
        'relay_id': uuid.UUID(rv['relay_id']),
        'public_key': PublicKey.parse(rv['public_key']),
        'token': rv['token'],
    }
Пример #7
0
def validate_register_response(public_key, data, signature, max_age=60 * 15):
    rv = json.loads(
        decode_str(
            rustcall(lib.semaphore_validate_register_response,
                     public_key._objptr, make_buf(data), encode_str(signature),
                     max_age)))
    return {
        'relay_id': uuid.UUID(rv['relay_id']),
        'token': rv['token'],
    }
Пример #8
0
def validate_register_response(public_key, data, signature, max_age=60 * 15):
    rv = json.loads(
        decode_str(
            rustcall(
                lib.semaphore_validate_register_response,
                public_key._objptr,
                make_buf(data),
                encode_str(signature),
                max_age,
            )
        )
    )
    return {"relay_id": uuid.UUID(rv["relay_id"]), "token": rv["token"]}
Пример #9
0
def create_register_challenge(data, signature, max_age=60 * 15):
    rv = json.loads(
        decode_str(
            rustcall(
                lib.semaphore_create_register_challenge,
                make_buf(data),
                encode_str(signature),
                max_age,
            )
        )
    )
    return {
        "relay_id": uuid.UUID(rv["relay_id"]),
        "public_key": PublicKey.parse(rv["public_key"]),
        "token": rv["token"],
    }
Пример #10
0
 def parse(cls, string):
     s = encode_str(string)
     ptr = rustcall(lib.semaphore_secretkey_parse, s)
     return cls._from_objptr(ptr)