Пример #1
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.relay_publickey_verify, buf, sig)
     return self._methodcall(lib.relay_publickey_verify_timestamp, buf, sig,
                             max_age)
Пример #2
0
def is_glob_match(
    value,
    pat,
    double_star=False,
    case_insensitive=False,
    path_normalize=False,
    allow_newline=False,
):
    flags = 0
    if double_star:
        flags |= lib.GLOB_FLAGS_DOUBLE_STAR
    if case_insensitive:
        flags |= lib.GLOB_FLAGS_CASE_INSENSITIVE
        # Since on the C side we're only working with bytes we need to lowercase the pattern
        # and value here.  This works with both bytes and unicode strings.
        value = value.lower()
        pat = pat.lower()
    if path_normalize:
        flags |= lib.GLOB_FLAGS_PATH_NORMALIZE
    if allow_newline:
        flags |= lib.GLOB_FLAGS_ALLOW_NEWLINE

    if isinstance(value, text_type):
        value = value.encode("utf-8")
    return rustcall(lib.relay_is_glob_match, make_buf(value), encode_str(pat), flags)
Пример #3
0
def create_register_challenge(data, signature, max_age=60 * 15):
    challenge_json = rustcall(
        lib.relay_create_register_challenge,
        make_buf(data),
        encode_str(signature),
        max_age,
    )

    challenge = json.loads(decode_str(challenge_json, free=True))
    return {
        "relay_id": uuid.UUID(challenge["relay_id"]),
        "public_key": PublicKey.parse(challenge["public_key"]),
        "token": challenge["token"],
    }
Пример #4
0
def validate_register_response(public_key, data, signature, max_age=60 * 15):
    response_json = rustcall(
        lib.relay_validate_register_response,
        public_key._objptr,
        make_buf(data),
        encode_str(signature),
        max_age,
    )

    response = json.loads(decode_str(response_json, free=True))
    return {
        "relay_id": uuid.UUID(response["relay_id"]),
        "token": response["token"]
    }
Пример #5
0
def validate_register_response(data, signature, secret, max_age=60):
    response_json = rustcall(
        lib.relay_validate_register_response,
        make_buf(data),
        encode_str(signature),
        encode_str(secret),
        max_age,
    )

    response = json.loads(decode_str(response_json, free=True))
    return {
        "relay_id": uuid.UUID(response["relay_id"]),
        "token": response["token"],
        "public_key": response["public_key"],
        "version": response["version"],
    }
Пример #6
0
 def sign(self, value):
     buf = make_buf(value)
     return decode_str(self._methodcall(lib.relay_secretkey_sign, buf),
                       free=True)
Пример #7
0
def get_register_response_relay_id(data):
    return decode_uuid(
        rustcall(lib.relay_get_register_response_relay_id, make_buf(data)))