Exemple #1
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))
Exemple #2
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'],
    }
Exemple #3
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'],
    }
Exemple #4
0
def split_chunks(string, remarks):
    return json.loads(
        decode_str(
            rustcall(
                lib.semaphore_split_chunks,
                encode_str(string),
                encode_str(json.dumps(remarks)),
            )
        )
    )
Exemple #5
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"]}
Exemple #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"],
    }
Exemple #7
0
 def __str__(self):
     return decode_str(
         self._methodcall(lib.semaphore_secretkey_to_string), free=True
     )
Exemple #8
0
 def sign(self, value):
     buf = make_buf(value)
     return decode_str(
         self._methodcall(lib.semaphore_secretkey_sign, buf), free=True
     )