@@ -47,13 +47,24 @@ def __init__(self, kty="", alg="", use="", kid="", x5c=None,
4747 if not isinstance (alg , str ):
4848 alg = as_unicode (alg )
4949
50- # The list comes from https://tools.ietf.org/html/rfc7518#page-6
51- # Should map against SIGNER_ALGS in cryptojwt.jws.jws
52- if alg not in ["HS256" , "HS384" , "HS512" , "RS256" , "RS384" ,
53- "RS512" , "ES256" , "ES384" , "ES512" , "PS256" ,
54- "PS384" , "PS512" , "none" ]:
55- raise UnsupportedAlgorithm ("Unknown algorithm: {}" .format (alg ))
56-
50+ if use == 'enc' :
51+ if alg not in ["RSA1_5" , "RSA-OAEP" , "RSA-OAEP-256" , "A128KW" , "A192KW" , "A256KW" ,
52+ "ECDH-ES" , "ECDH-ES+A128KW" , "ECDH-ES+A192KW" , "ECDH-ES+A256KW" ]:
53+ raise UnsupportedAlgorithm ("Unknown algorithm: {}" .format (alg ))
54+ elif use == 'sig' :
55+ # The list comes from https://tools.ietf.org/html/rfc7518#page-6
56+ # Should map against SIGNER_ALGS in cryptojwt.jws.jws
57+ if alg not in ["HS256" , "HS384" , "HS512" , "RS256" , "RS384" ,
58+ "RS512" , "ES256" , "ES384" , "ES512" , "PS256" ,
59+ "PS384" , "PS512" , "none" ]:
60+ raise UnsupportedAlgorithm ("Unknown algorithm: {}" .format (alg ))
61+ else : # potentially used both for encryption and signing
62+ if alg not in ["HS256" , "HS384" , "HS512" , "RS256" , "RS384" ,
63+ "RS512" , "ES256" , "ES384" , "ES512" , "PS256" ,
64+ "PS384" , "PS512" , "none" , "RSA1_5" , "RSA-OAEP" , "RSA-OAEP-256" ,
65+ "A128KW" , "A192KW" , "A256KW" , "ECDH-ES" , "ECDH-ES+A128KW" ,
66+ "ECDH-ES+A192KW" , "ECDH-ES+A256KW" ]:
67+ raise UnsupportedAlgorithm ("Unknown algorithm: {}" .format (alg ))
5768 self .alg = alg
5869
5970 if isinstance (use , str ):
0 commit comments