def test_parse_and_get_label(self): assert CryptoKey.parse_and_get_label( self.valid_key, "p256ecdsa") == ("BF92zdI_AKcH5Q31_Rr-04bPqOHU_Qg6lAawHbvfQrY" "xV_vIsAsHSyaiuyfofvxT8ZVIXccykd4V2Z7iJVfreT8") assert CryptoKey.parse_and_get_label(self.valid_key, "missing") is None assert CryptoKey.parse_and_get_label("invalid key", "missing") is None
def validate_crypto_key(self, value): if CryptoKey.parse_and_get_label(value, "dh"): raise InvalidRequest( "Do not include 'dh' in aes128gcm " "Crypto-Key header", status_code=400, errno=110)
def validate_encryption(self, value): if CryptoKey.parse_and_get_label(value, "salt"): raise InvalidRequest( "Do not include 'salt' in aes128gcm " "Encryption header", status_code=400, errno=110)
def validate_crypto_key(self, value): """Must contain a dh value""" dh = CryptoKey.parse_and_get_label(value, "dh") if not dh or not VALID_BASE64_URL.match("dh"): raise InvalidRequest("Invalid dh value in Encryption-Key header", status_code=400, errno=110)
def validate_encryption(self, value): """Must contain a salt value""" salt = CryptoKey.parse_and_get_label(value, "salt") if not salt or not VALID_BASE64_URL.match(salt): raise InvalidRequest("Invalid salt value in Encryption header", status_code=400, errno=110)
def validate_crypto_key(self, value): """Must not contain a dh value""" dh = CryptoKey.parse_and_get_label(value, "dh") if dh: raise InvalidRequest( "dh value in Crypto-Key header not valid for 01 or earlier " "webpush-encryption", status_code=400, errno=110, )