repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/ec.py | ec_construct_public | def ec_construct_public(num):
"""
Given a set of values on public attributes build a elliptic curve
public key instance.
:param num: A dictionary with public attributes and their values
:return: A
cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey
instance.
"""
... | python | def ec_construct_public(num):
"""
Given a set of values on public attributes build a elliptic curve
public key instance.
:param num: A dictionary with public attributes and their values
:return: A
cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey
instance.
"""
... | [
"def",
"ec_construct_public",
"(",
"num",
")",
":",
"ecpn",
"=",
"ec",
".",
"EllipticCurvePublicNumbers",
"(",
"num",
"[",
"'x'",
"]",
",",
"num",
"[",
"'y'",
"]",
",",
"NIST2SEC",
"[",
"as_unicode",
"(",
"num",
"[",
"'crv'",
"]",
")",
"]",
"(",
")",... | Given a set of values on public attributes build a elliptic curve
public key instance.
:param num: A dictionary with public attributes and their values
:return: A
cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey
instance. | [
"Given",
"a",
"set",
"of",
"values",
"on",
"public",
"attributes",
"build",
"a",
"elliptic",
"curve",
"public",
"key",
"instance",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/ec.py#L32-L44 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/ec.py | ec_construct_private | def ec_construct_private(num):
"""
Given a set of values on public and private attributes build a elliptic
curve private key instance.
:param num: A dictionary with public and private attributes and their values
:return: A
cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey... | python | def ec_construct_private(num):
"""
Given a set of values on public and private attributes build a elliptic
curve private key instance.
:param num: A dictionary with public and private attributes and their values
:return: A
cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey... | [
"def",
"ec_construct_private",
"(",
"num",
")",
":",
"pub_ecpn",
"=",
"ec",
".",
"EllipticCurvePublicNumbers",
"(",
"num",
"[",
"'x'",
"]",
",",
"num",
"[",
"'y'",
"]",
",",
"NIST2SEC",
"[",
"as_unicode",
"(",
"num",
"[",
"'crv'",
"]",
")",
"]",
"(",
... | Given a set of values on public and private attributes build a elliptic
curve private key instance.
:param num: A dictionary with public and private attributes and their values
:return: A
cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey
instance. | [
"Given",
"a",
"set",
"of",
"values",
"on",
"public",
"and",
"private",
"attributes",
"build",
"a",
"elliptic",
"curve",
"private",
"key",
"instance",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/ec.py#L47-L60 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/ec.py | import_private_key_from_file | def import_private_key_from_file(filename, passphrase=None):
"""
Read a private Elliptic Curve key from a PEM file.
:param filename: The name of the file
:param passphrase: A pass phrase to use to unpack the PEM file.
:return: A
cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePriv... | python | def import_private_key_from_file(filename, passphrase=None):
"""
Read a private Elliptic Curve key from a PEM file.
:param filename: The name of the file
:param passphrase: A pass phrase to use to unpack the PEM file.
:return: A
cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePriv... | [
"def",
"import_private_key_from_file",
"(",
"filename",
",",
"passphrase",
"=",
"None",
")",
":",
"with",
"open",
"(",
"filename",
",",
"\"rb\"",
")",
"as",
"key_file",
":",
"private_key",
"=",
"serialization",
".",
"load_pem_private_key",
"(",
"key_file",
".",
... | Read a private Elliptic Curve key from a PEM file.
:param filename: The name of the file
:param passphrase: A pass phrase to use to unpack the PEM file.
:return: A
cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey
instance | [
"Read",
"a",
"private",
"Elliptic",
"Curve",
"key",
"from",
"a",
"PEM",
"file",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/ec.py#L63-L79 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/ec.py | ECKey.deserialize | def deserialize(self):
"""
Starting with information gathered from the on-the-wire representation
of an elliptic curve key (a JWK) initiate an
cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey
or EllipticCurvePrivateKey instance. So we have to get from having::
... | python | def deserialize(self):
"""
Starting with information gathered from the on-the-wire representation
of an elliptic curve key (a JWK) initiate an
cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey
or EllipticCurvePrivateKey instance. So we have to get from having::
... | [
"def",
"deserialize",
"(",
"self",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"x",
",",
"(",
"str",
",",
"bytes",
")",
")",
":",
"_x",
"=",
"deser",
"(",
"self",
".",
"x",
")",
"else",
":",
"raise",
"ValueError",
"(",
"'\"x\" MUST be a string'",... | Starting with information gathered from the on-the-wire representation
of an elliptic curve key (a JWK) initiate an
cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePublicKey
or EllipticCurvePrivateKey instance. So we have to get from having::
{
"kty":"EC",
... | [
"Starting",
"with",
"information",
"gathered",
"from",
"the",
"on",
"-",
"the",
"-",
"wire",
"representation",
"of",
"an",
"elliptic",
"curve",
"key",
"(",
"a",
"JWK",
")",
"initiate",
"an",
"cryptography",
".",
"hazmat",
".",
"primitives",
".",
"asymmetric"... | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/ec.py#L142-L188 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/ec.py | ECKey.serialize | def serialize(self, private=False):
"""
Go from a
cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey
or EllipticCurvePublicKey instance to a JWK representation.
:param private: Whether we should include the private attributes or not.
:return: A JWK as a... | python | def serialize(self, private=False):
"""
Go from a
cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey
or EllipticCurvePublicKey instance to a JWK representation.
:param private: Whether we should include the private attributes or not.
:return: A JWK as a... | [
"def",
"serialize",
"(",
"self",
",",
"private",
"=",
"False",
")",
":",
"if",
"self",
".",
"priv_key",
":",
"self",
".",
"_serialize",
"(",
"self",
".",
"priv_key",
")",
"else",
":",
"self",
".",
"_serialize",
"(",
"self",
".",
"pub_key",
")",
"res"... | Go from a
cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey
or EllipticCurvePublicKey instance to a JWK representation.
:param private: Whether we should include the private attributes or not.
:return: A JWK as a dictionary | [
"Go",
"from",
"a",
"cryptography",
".",
"hazmat",
".",
"primitives",
".",
"asymmetric",
".",
"ec",
".",
"EllipticCurvePrivateKey",
"or",
"EllipticCurvePublicKey",
"instance",
"to",
"a",
"JWK",
"representation",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/ec.py#L203-L228 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/ec.py | ECKey.load_key | def load_key(self, key):
"""
Load an Elliptic curve key
:param key: An elliptic curve key instance, private or public.
:return: Reference to this instance
"""
self._serialize(key)
if isinstance(key, ec.EllipticCurvePrivateKey):
self.priv_key = key
... | python | def load_key(self, key):
"""
Load an Elliptic curve key
:param key: An elliptic curve key instance, private or public.
:return: Reference to this instance
"""
self._serialize(key)
if isinstance(key, ec.EllipticCurvePrivateKey):
self.priv_key = key
... | [
"def",
"load_key",
"(",
"self",
",",
"key",
")",
":",
"self",
".",
"_serialize",
"(",
"key",
")",
"if",
"isinstance",
"(",
"key",
",",
"ec",
".",
"EllipticCurvePrivateKey",
")",
":",
"self",
".",
"priv_key",
"=",
"key",
"self",
".",
"pub_key",
"=",
"... | Load an Elliptic curve key
:param key: An elliptic curve key instance, private or public.
:return: Reference to this instance | [
"Load",
"an",
"Elliptic",
"curve",
"key"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/ec.py#L230-L244 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | rsa_init | def rsa_init(spec):
"""
Initiates a :py:class:`oidcmsg.keybundle.KeyBundle` instance
containing newly minted RSA keys according to a spec.
Example of specification::
{'size':2048, 'use': ['enc', 'sig'] }
Using the spec above 2 RSA keys would be minted, one for
encryption ... | python | def rsa_init(spec):
"""
Initiates a :py:class:`oidcmsg.keybundle.KeyBundle` instance
containing newly minted RSA keys according to a spec.
Example of specification::
{'size':2048, 'use': ['enc', 'sig'] }
Using the spec above 2 RSA keys would be minted, one for
encryption ... | [
"def",
"rsa_init",
"(",
"spec",
")",
":",
"try",
":",
"size",
"=",
"spec",
"[",
"'size'",
"]",
"except",
"KeyError",
":",
"size",
"=",
"2048",
"kb",
"=",
"KeyBundle",
"(",
"keytype",
"=",
"\"RSA\"",
")",
"if",
"'use'",
"in",
"spec",
":",
"for",
"us... | Initiates a :py:class:`oidcmsg.keybundle.KeyBundle` instance
containing newly minted RSA keys according to a spec.
Example of specification::
{'size':2048, 'use': ['enc', 'sig'] }
Using the spec above 2 RSA keys would be minted, one for
encryption and one for signing.
... | [
"Initiates",
"a",
":",
"py",
":",
"class",
":",
"oidcmsg",
".",
"keybundle",
".",
"KeyBundle",
"instance",
"containing",
"newly",
"minted",
"RSA",
"keys",
"according",
"to",
"a",
"spec",
".",
"Example",
"of",
"specification",
"::",
"{",
"size",
":",
"2048"... | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L56-L85 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | ec_init | def ec_init(spec):
"""
Initiate a key bundle with an elliptic curve key.
:param spec: Key specifics of the form::
{"type": "EC", "crv": "P-256", "use": ["sig"]}
:return: A KeyBundle instance
"""
kb = KeyBundle(keytype="EC")
if 'use' in spec:
for use in spec["use"]:
... | python | def ec_init(spec):
"""
Initiate a key bundle with an elliptic curve key.
:param spec: Key specifics of the form::
{"type": "EC", "crv": "P-256", "use": ["sig"]}
:return: A KeyBundle instance
"""
kb = KeyBundle(keytype="EC")
if 'use' in spec:
for use in spec["use"]:
... | [
"def",
"ec_init",
"(",
"spec",
")",
":",
"kb",
"=",
"KeyBundle",
"(",
"keytype",
"=",
"\"EC\"",
")",
"if",
"'use'",
"in",
"spec",
":",
"for",
"use",
"in",
"spec",
"[",
"\"use\"",
"]",
":",
"eck",
"=",
"new_ec_key",
"(",
"crv",
"=",
"spec",
"[",
"... | Initiate a key bundle with an elliptic curve key.
:param spec: Key specifics of the form::
{"type": "EC", "crv": "P-256", "use": ["sig"]}
:return: A KeyBundle instance | [
"Initiate",
"a",
"key",
"bundle",
"with",
"an",
"elliptic",
"curve",
"key",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L88-L107 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | keybundle_from_local_file | def keybundle_from_local_file(filename, typ, usage):
"""
Create a KeyBundle based on the content in a local file
:param filename: Name of the file
:param typ: Type of content
:param usage: What the key should be used for
:return: The created KeyBundle
"""
usage = harmonize_usage(us... | python | def keybundle_from_local_file(filename, typ, usage):
"""
Create a KeyBundle based on the content in a local file
:param filename: Name of the file
:param typ: Type of content
:param usage: What the key should be used for
:return: The created KeyBundle
"""
usage = harmonize_usage(us... | [
"def",
"keybundle_from_local_file",
"(",
"filename",
",",
"typ",
",",
"usage",
")",
":",
"usage",
"=",
"harmonize_usage",
"(",
"usage",
")",
"if",
"typ",
".",
"lower",
"(",
")",
"==",
"\"jwks\"",
":",
"kb",
"=",
"KeyBundle",
"(",
"source",
"=",
"filename... | Create a KeyBundle based on the content in a local file
:param filename: Name of the file
:param typ: Type of content
:param usage: What the key should be used for
:return: The created KeyBundle | [
"Create",
"a",
"KeyBundle",
"based",
"on",
"the",
"content",
"in",
"a",
"local",
"file",
":",
"param",
"filename",
":",
"Name",
"of",
"the",
"file",
":",
"param",
"typ",
":",
"Type",
"of",
"content",
":",
"param",
"usage",
":",
"What",
"the",
"key",
... | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L573-L591 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | dump_jwks | def dump_jwks(kbl, target, private=False):
"""
Write a JWK to a file. Will ignore symmetric keys !!
:param kbl: List of KeyBundles
:param target: Name of the file to which everything should be written
:param private: Should also the private parts be exported
"""
keys = []
for kb in kbl... | python | def dump_jwks(kbl, target, private=False):
"""
Write a JWK to a file. Will ignore symmetric keys !!
:param kbl: List of KeyBundles
:param target: Name of the file to which everything should be written
:param private: Should also the private parts be exported
"""
keys = []
for kb in kbl... | [
"def",
"dump_jwks",
"(",
"kbl",
",",
"target",
",",
"private",
"=",
"False",
")",
":",
"keys",
"=",
"[",
"]",
"for",
"kb",
"in",
"kbl",
":",
"keys",
".",
"extend",
"(",
"[",
"k",
".",
"serialize",
"(",
"private",
")",
"for",
"k",
"in",
"kb",
".... | Write a JWK to a file. Will ignore symmetric keys !!
:param kbl: List of KeyBundles
:param target: Name of the file to which everything should be written
:param private: Should also the private parts be exported | [
"Write",
"a",
"JWK",
"to",
"a",
"file",
".",
"Will",
"ignore",
"symmetric",
"keys",
"!!"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L594-L618 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | build_key_bundle | def build_key_bundle(key_conf, kid_template=""):
"""
Builds a :py:class:`oidcmsg.key_bundle.KeyBundle` instance based on a key
specification.
An example of such a specification::
keys = [
{"type": "RSA", "key": "cp_keys/key.pem", "use": ["enc", "sig"]},
{"type": "EC", "... | python | def build_key_bundle(key_conf, kid_template=""):
"""
Builds a :py:class:`oidcmsg.key_bundle.KeyBundle` instance based on a key
specification.
An example of such a specification::
keys = [
{"type": "RSA", "key": "cp_keys/key.pem", "use": ["enc", "sig"]},
{"type": "EC", "... | [
"def",
"build_key_bundle",
"(",
"key_conf",
",",
"kid_template",
"=",
"\"\"",
")",
":",
"kid",
"=",
"0",
"tot_kb",
"=",
"KeyBundle",
"(",
")",
"for",
"spec",
"in",
"key_conf",
":",
"typ",
"=",
"spec",
"[",
"\"type\"",
"]",
".",
"upper",
"(",
")",
"if... | Builds a :py:class:`oidcmsg.key_bundle.KeyBundle` instance based on a key
specification.
An example of such a specification::
keys = [
{"type": "RSA", "key": "cp_keys/key.pem", "use": ["enc", "sig"]},
{"type": "EC", "crv": "P-256", "use": ["sig"], "kid": "ec.1"},
{"... | [
"Builds",
"a",
":",
"py",
":",
"class",
":",
"oidcmsg",
".",
"key_bundle",
".",
"KeyBundle",
"instance",
"based",
"on",
"a",
"key",
"specification",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L621-L698 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | sort_func | def sort_func(kd1, kd2):
"""
Compares 2 key descriptions
:param kd1: First key description
:param kd2: Second key description
:return: -1,0,1 depending on whether kd1 le,eq or gt then kd2
"""
_l = _cmp(kd1['type'], kd2['type'])
if _l:
return _l
if kd1['type'] == 'EC':
... | python | def sort_func(kd1, kd2):
"""
Compares 2 key descriptions
:param kd1: First key description
:param kd2: Second key description
:return: -1,0,1 depending on whether kd1 le,eq or gt then kd2
"""
_l = _cmp(kd1['type'], kd2['type'])
if _l:
return _l
if kd1['type'] == 'EC':
... | [
"def",
"sort_func",
"(",
"kd1",
",",
"kd2",
")",
":",
"_l",
"=",
"_cmp",
"(",
"kd1",
"[",
"'type'",
"]",
",",
"kd2",
"[",
"'type'",
"]",
")",
"if",
"_l",
":",
"return",
"_l",
"if",
"kd1",
"[",
"'type'",
"]",
"==",
"'EC'",
":",
"_l",
"=",
"_cm... | Compares 2 key descriptions
:param kd1: First key description
:param kd2: Second key description
:return: -1,0,1 depending on whether kd1 le,eq or gt then kd2 | [
"Compares",
"2",
"key",
"descriptions",
":",
"param",
"kd1",
":",
"First",
"key",
"description",
":",
"param",
"kd2",
":",
"Second",
"key",
"description",
":",
"return",
":",
"-",
"1",
"0",
"1",
"depending",
"on",
"whether",
"kd1",
"le",
"eq",
"or",
"g... | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L717-L758 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | order_key_defs | def order_key_defs(key_def):
"""
Sort a set of key definitions. A key definition that defines more then
one usage type are splitted into as many definitions as the number of
usage types specified. One key definition per usage type.
:param key_def: A set of key definitions
:return: The set of de... | python | def order_key_defs(key_def):
"""
Sort a set of key definitions. A key definition that defines more then
one usage type are splitted into as many definitions as the number of
usage types specified. One key definition per usage type.
:param key_def: A set of key definitions
:return: The set of de... | [
"def",
"order_key_defs",
"(",
"key_def",
")",
":",
"_int",
"=",
"[",
"]",
"# First make sure all defs only reference one usage",
"for",
"kd",
"in",
"key_def",
":",
"if",
"len",
"(",
"kd",
"[",
"'use'",
"]",
")",
">",
"1",
":",
"for",
"_use",
"in",
"kd",
... | Sort a set of key definitions. A key definition that defines more then
one usage type are splitted into as many definitions as the number of
usage types specified. One key definition per usage type.
:param key_def: A set of key definitions
:return: The set of definitions as a sorted list | [
"Sort",
"a",
"set",
"of",
"key",
"definitions",
".",
"A",
"key",
"definition",
"that",
"defines",
"more",
"then",
"one",
"usage",
"type",
"are",
"splitted",
"into",
"as",
"many",
"definitions",
"as",
"the",
"number",
"of",
"usage",
"types",
"specified",
".... | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L761-L783 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | key_diff | def key_diff(key_bundle, key_defs):
"""
Creates a difference dictionary with keys that should added and keys that
should be deleted from a Key Bundle to get it updated to a state that
mirrors What is in the key_defs specification.
:param key_bundle: The original KeyBundle
:param key_defs: A set... | python | def key_diff(key_bundle, key_defs):
"""
Creates a difference dictionary with keys that should added and keys that
should be deleted from a Key Bundle to get it updated to a state that
mirrors What is in the key_defs specification.
:param key_bundle: The original KeyBundle
:param key_defs: A set... | [
"def",
"key_diff",
"(",
"key_bundle",
",",
"key_defs",
")",
":",
"keys",
"=",
"key_bundle",
".",
"get",
"(",
")",
"diff",
"=",
"{",
"}",
"# My own sorted copy",
"key_defs",
"=",
"order_key_defs",
"(",
"key_defs",
")",
"[",
":",
"]",
"used",
"=",
"[",
"... | Creates a difference dictionary with keys that should added and keys that
should be deleted from a Key Bundle to get it updated to a state that
mirrors What is in the key_defs specification.
:param key_bundle: The original KeyBundle
:param key_defs: A set of key definitions
:return: A dictionary wi... | [
"Creates",
"a",
"difference",
"dictionary",
"with",
"keys",
"that",
"should",
"added",
"and",
"keys",
"that",
"should",
"be",
"deleted",
"from",
"a",
"Key",
"Bundle",
"to",
"get",
"it",
"updated",
"to",
"a",
"state",
"that",
"mirrors",
"What",
"is",
"in",
... | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L786-L842 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | update_key_bundle | def update_key_bundle(key_bundle, diff):
"""
Apply a diff specification to a KeyBundle.
The keys that are to be added are added.
The keys that should be deleted are marked as inactive.
:param key_bundle: The original KeyBundle
:param diff: The difference specification
:return: An updated ke... | python | def update_key_bundle(key_bundle, diff):
"""
Apply a diff specification to a KeyBundle.
The keys that are to be added are added.
The keys that should be deleted are marked as inactive.
:param key_bundle: The original KeyBundle
:param diff: The difference specification
:return: An updated ke... | [
"def",
"update_key_bundle",
"(",
"key_bundle",
",",
"diff",
")",
":",
"try",
":",
"_add",
"=",
"diff",
"[",
"'add'",
"]",
"except",
"KeyError",
":",
"pass",
"else",
":",
"key_bundle",
".",
"extend",
"(",
"_add",
")",
"try",
":",
"_del",
"=",
"diff",
... | Apply a diff specification to a KeyBundle.
The keys that are to be added are added.
The keys that should be deleted are marked as inactive.
:param key_bundle: The original KeyBundle
:param diff: The difference specification
:return: An updated key_bundle | [
"Apply",
"a",
"diff",
"specification",
"to",
"a",
"KeyBundle",
".",
"The",
"keys",
"that",
"are",
"to",
"be",
"added",
"are",
"added",
".",
"The",
"keys",
"that",
"should",
"be",
"deleted",
"are",
"marked",
"as",
"inactive",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L845-L869 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | key_rollover | def key_rollover(kb):
"""
A nifty function that lets you do a key rollover that encompasses creating
a completely new set of keys. One new per every old one. With the same
specifications as the old one.
All the old ones are marked as inactive.
:param kb:
:return:
"""
key_spec = []
... | python | def key_rollover(kb):
"""
A nifty function that lets you do a key rollover that encompasses creating
a completely new set of keys. One new per every old one. With the same
specifications as the old one.
All the old ones are marked as inactive.
:param kb:
:return:
"""
key_spec = []
... | [
"def",
"key_rollover",
"(",
"kb",
")",
":",
"key_spec",
"=",
"[",
"]",
"for",
"key",
"in",
"kb",
".",
"get",
"(",
")",
":",
"_spec",
"=",
"{",
"'type'",
":",
"key",
".",
"kty",
",",
"'use'",
":",
"[",
"key",
".",
"use",
"]",
"}",
"if",
"key",... | A nifty function that lets you do a key rollover that encompasses creating
a completely new set of keys. One new per every old one. With the same
specifications as the old one.
All the old ones are marked as inactive.
:param kb:
:return: | [
"A",
"nifty",
"function",
"that",
"lets",
"you",
"do",
"a",
"key",
"rollover",
"that",
"encompasses",
"creating",
"a",
"completely",
"new",
"set",
"of",
"keys",
".",
"One",
"new",
"per",
"every",
"old",
"one",
".",
"With",
"the",
"same",
"specifications",
... | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L872-L895 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | KeyBundle.do_keys | def do_keys(self, keys):
"""
Go from JWK description to binary keys
:param keys:
:return:
"""
for inst in keys:
typ = inst["kty"]
try:
_usage = harmonize_usage(inst['use'])
except KeyError:
_usage = ['']... | python | def do_keys(self, keys):
"""
Go from JWK description to binary keys
:param keys:
:return:
"""
for inst in keys:
typ = inst["kty"]
try:
_usage = harmonize_usage(inst['use'])
except KeyError:
_usage = ['']... | [
"def",
"do_keys",
"(",
"self",
",",
"keys",
")",
":",
"for",
"inst",
"in",
"keys",
":",
"typ",
"=",
"inst",
"[",
"\"kty\"",
"]",
"try",
":",
"_usage",
"=",
"harmonize_usage",
"(",
"inst",
"[",
"'use'",
"]",
")",
"except",
"KeyError",
":",
"_usage",
... | Go from JWK description to binary keys
:param keys:
:return: | [
"Go",
"from",
"JWK",
"description",
"to",
"binary",
"keys"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L185-L217 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | KeyBundle.do_local_jwk | def do_local_jwk(self, filename):
"""
Load a JWKS from a local file
:param filename:
"""
_info = json.loads(open(filename).read())
if 'keys' in _info:
self.do_keys(_info["keys"])
else:
self.do_keys([_info])
self.last_upd... | python | def do_local_jwk(self, filename):
"""
Load a JWKS from a local file
:param filename:
"""
_info = json.loads(open(filename).read())
if 'keys' in _info:
self.do_keys(_info["keys"])
else:
self.do_keys([_info])
self.last_upd... | [
"def",
"do_local_jwk",
"(",
"self",
",",
"filename",
")",
":",
"_info",
"=",
"json",
".",
"loads",
"(",
"open",
"(",
"filename",
")",
".",
"read",
"(",
")",
")",
"if",
"'keys'",
"in",
"_info",
":",
"self",
".",
"do_keys",
"(",
"_info",
"[",
"\"keys... | Load a JWKS from a local file
:param filename: | [
"Load",
"a",
"JWKS",
"from",
"a",
"local",
"file",
":",
"param",
"filename",
":"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L219-L231 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | KeyBundle.do_local_der | def do_local_der(self, filename, keytype, keyusage=None, kid=''):
"""
Load a DER encoded file amd create a key from it.
:param filename:
:param keytype: Presently only 'rsa' supported
:param keyusage: encryption ('enc') or signing ('sig') or both
"""
_b... | python | def do_local_der(self, filename, keytype, keyusage=None, kid=''):
"""
Load a DER encoded file amd create a key from it.
:param filename:
:param keytype: Presently only 'rsa' supported
:param keyusage: encryption ('enc') or signing ('sig') or both
"""
_b... | [
"def",
"do_local_der",
"(",
"self",
",",
"filename",
",",
"keytype",
",",
"keyusage",
"=",
"None",
",",
"kid",
"=",
"''",
")",
":",
"_bkey",
"=",
"import_private_rsa_key_from_file",
"(",
"filename",
")",
"if",
"keytype",
".",
"lower",
"(",
")",
"!=",
"'r... | Load a DER encoded file amd create a key from it.
:param filename:
:param keytype: Presently only 'rsa' supported
:param keyusage: encryption ('enc') or signing ('sig') or both | [
"Load",
"a",
"DER",
"encoded",
"file",
"amd",
"create",
"a",
"key",
"from",
"it",
".",
":",
"param",
"filename",
":",
":",
"param",
"keytype",
":",
"Presently",
"only",
"rsa",
"supported",
":",
"param",
"keyusage",
":",
"encryption",
"(",
"enc",
")",
"... | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L233-L258 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | KeyBundle.do_remote | def do_remote(self):
"""
Load a JWKS from a webpage
:return: True or False if load was successful
"""
if self.verify_ssl:
args = {"verify": self.verify_ssl}
else:
args = {}
try:
logging.debug('KeyBundle fetch keys from... | python | def do_remote(self):
"""
Load a JWKS from a webpage
:return: True or False if load was successful
"""
if self.verify_ssl:
args = {"verify": self.verify_ssl}
else:
args = {}
try:
logging.debug('KeyBundle fetch keys from... | [
"def",
"do_remote",
"(",
"self",
")",
":",
"if",
"self",
".",
"verify_ssl",
":",
"args",
"=",
"{",
"\"verify\"",
":",
"self",
".",
"verify_ssl",
"}",
"else",
":",
"args",
"=",
"{",
"}",
"try",
":",
"logging",
".",
"debug",
"(",
"'KeyBundle fetch keys f... | Load a JWKS from a webpage
:return: True or False if load was successful | [
"Load",
"a",
"JWKS",
"from",
"a",
"webpage"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L260-L298 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | KeyBundle._parse_remote_response | def _parse_remote_response(self, response):
"""
Parse JWKS from the HTTP response.
Should be overriden by subclasses for adding support of e.g. signed
JWKS.
:param response: HTTP response from the 'jwks_uri' endpoint
:return: response parsed as JSON
"""
#... | python | def _parse_remote_response(self, response):
"""
Parse JWKS from the HTTP response.
Should be overriden by subclasses for adding support of e.g. signed
JWKS.
:param response: HTTP response from the 'jwks_uri' endpoint
:return: response parsed as JSON
"""
#... | [
"def",
"_parse_remote_response",
"(",
"self",
",",
"response",
")",
":",
"# Check if the content type is the right one.",
"try",
":",
"if",
"response",
".",
"headers",
"[",
"\"Content-Type\"",
"]",
"!=",
"'application/json'",
":",
"logger",
".",
"warning",
"(",
"'Wr... | Parse JWKS from the HTTP response.
Should be overriden by subclasses for adding support of e.g. signed
JWKS.
:param response: HTTP response from the 'jwks_uri' endpoint
:return: response parsed as JSON | [
"Parse",
"JWKS",
"from",
"the",
"HTTP",
"response",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L300-L321 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | KeyBundle.update | def update(self):
"""
Reload the keys if necessary
This is a forced update, will happen even if cache time has not elapsed.
Replaced keys will be marked as inactive and not removed.
"""
res = True # An update was successful
if self.source:
_k... | python | def update(self):
"""
Reload the keys if necessary
This is a forced update, will happen even if cache time has not elapsed.
Replaced keys will be marked as inactive and not removed.
"""
res = True # An update was successful
if self.source:
_k... | [
"def",
"update",
"(",
"self",
")",
":",
"res",
"=",
"True",
"# An update was successful",
"if",
"self",
".",
"source",
":",
"_keys",
"=",
"self",
".",
"_keys",
"# just in case",
"# reread everything",
"self",
".",
"_keys",
"=",
"[",
"]",
"try",
":",
"if",
... | Reload the keys if necessary
This is a forced update, will happen even if cache time has not elapsed.
Replaced keys will be marked as inactive and not removed. | [
"Reload",
"the",
"keys",
"if",
"necessary",
"This",
"is",
"a",
"forced",
"update",
"will",
"happen",
"even",
"if",
"cache",
"time",
"has",
"not",
"elapsed",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L335-L370 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | KeyBundle.get | def get(self, typ="", only_active=True):
"""
Return a list of keys. Either all keys or only keys of a specific type
:param typ: Type of key (rsa, ec, oct, ..)
:return: If typ is undefined all the keys as a dictionary
otherwise the appropriate keys in a list
"... | python | def get(self, typ="", only_active=True):
"""
Return a list of keys. Either all keys or only keys of a specific type
:param typ: Type of key (rsa, ec, oct, ..)
:return: If typ is undefined all the keys as a dictionary
otherwise the appropriate keys in a list
"... | [
"def",
"get",
"(",
"self",
",",
"typ",
"=",
"\"\"",
",",
"only_active",
"=",
"True",
")",
":",
"self",
".",
"_uptodate",
"(",
")",
"_typs",
"=",
"[",
"typ",
".",
"lower",
"(",
")",
",",
"typ",
".",
"upper",
"(",
")",
"]",
"if",
"typ",
":",
"_... | Return a list of keys. Either all keys or only keys of a specific type
:param typ: Type of key (rsa, ec, oct, ..)
:return: If typ is undefined all the keys as a dictionary
otherwise the appropriate keys in a list | [
"Return",
"a",
"list",
"of",
"keys",
".",
"Either",
"all",
"keys",
"or",
"only",
"keys",
"of",
"a",
"specific",
"type",
":",
"param",
"typ",
":",
"Type",
"of",
"key",
"(",
"rsa",
"ec",
"oct",
"..",
")",
":",
"return",
":",
"If",
"typ",
"is",
"und... | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L372-L391 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | KeyBundle.remove_keys_by_type | def remove_keys_by_type(self, typ):
"""
Remove keys that are of a specific type.
:param typ: Type of key (rsa, ec, oct, ..)
"""
_typs = [typ.lower(), typ.upper()]
self._keys = [k for k in self._keys if not k.kty in _typs] | python | def remove_keys_by_type(self, typ):
"""
Remove keys that are of a specific type.
:param typ: Type of key (rsa, ec, oct, ..)
"""
_typs = [typ.lower(), typ.upper()]
self._keys = [k for k in self._keys if not k.kty in _typs] | [
"def",
"remove_keys_by_type",
"(",
"self",
",",
"typ",
")",
":",
"_typs",
"=",
"[",
"typ",
".",
"lower",
"(",
")",
",",
"typ",
".",
"upper",
"(",
")",
"]",
"self",
".",
"_keys",
"=",
"[",
"k",
"for",
"k",
"in",
"self",
".",
"_keys",
"if",
"not"... | Remove keys that are of a specific type.
:param typ: Type of key (rsa, ec, oct, ..) | [
"Remove",
"keys",
"that",
"are",
"of",
"a",
"specific",
"type",
".",
":",
"param",
"typ",
":",
"Type",
"of",
"key",
"(",
"rsa",
"ec",
"oct",
"..",
")"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L415-L422 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | KeyBundle.jwks | def jwks(self, private=False):
"""
Create a JWKS as a JSON document
:param private: Whether private key information should be included.
:return: A JWKS JSON representation of the keys in this bundle
"""
self._uptodate()
keys = list()
for k in self... | python | def jwks(self, private=False):
"""
Create a JWKS as a JSON document
:param private: Whether private key information should be included.
:return: A JWKS JSON representation of the keys in this bundle
"""
self._uptodate()
keys = list()
for k in self... | [
"def",
"jwks",
"(",
"self",
",",
"private",
"=",
"False",
")",
":",
"self",
".",
"_uptodate",
"(",
")",
"keys",
"=",
"list",
"(",
")",
"for",
"k",
"in",
"self",
".",
"_keys",
":",
"if",
"private",
":",
"key",
"=",
"k",
".",
"serialize",
"(",
"p... | Create a JWKS as a JSON document
:param private: Whether private key information should be included.
:return: A JWKS JSON representation of the keys in this bundle | [
"Create",
"a",
"JWKS",
"as",
"a",
"JSON",
"document",
":",
"param",
"private",
":",
"Whether",
"private",
"key",
"information",
"should",
"be",
"included",
".",
":",
"return",
":",
"A",
"JWKS",
"JSON",
"representation",
"of",
"the",
"keys",
"in",
"this",
... | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L427-L444 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | KeyBundle.get_key_with_kid | def get_key_with_kid(self, kid):
"""
Return the key that has a specific key ID (kid)
:param kid: The Key ID
:return: The key or None
"""
for key in self._keys:
if key.kid == kid:
return key
# Try updating since there might ha... | python | def get_key_with_kid(self, kid):
"""
Return the key that has a specific key ID (kid)
:param kid: The Key ID
:return: The key or None
"""
for key in self._keys:
if key.kid == kid:
return key
# Try updating since there might ha... | [
"def",
"get_key_with_kid",
"(",
"self",
",",
"kid",
")",
":",
"for",
"key",
"in",
"self",
".",
"_keys",
":",
"if",
"key",
".",
"kid",
"==",
"kid",
":",
"return",
"key",
"# Try updating since there might have been an update to the key file",
"self",
".",
"update"... | Return the key that has a specific key ID (kid)
:param kid: The Key ID
:return: The key or None | [
"Return",
"the",
"key",
"that",
"has",
"a",
"specific",
"key",
"ID",
"(",
"kid",
")",
":",
"param",
"kid",
":",
"The",
"Key",
"ID",
":",
"return",
":",
"The",
"key",
"or",
"None"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L476-L494 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | KeyBundle.kids | def kids(self):
"""
Return a list of key IDs. Note that this list may be shorter then
the list of keys. The reason might be that there are some keys with
no key ID.
:return: A list of all the key IDs that exists in this bundle
"""
self._uptodate()
... | python | def kids(self):
"""
Return a list of key IDs. Note that this list may be shorter then
the list of keys. The reason might be that there are some keys with
no key ID.
:return: A list of all the key IDs that exists in this bundle
"""
self._uptodate()
... | [
"def",
"kids",
"(",
"self",
")",
":",
"self",
".",
"_uptodate",
"(",
")",
"return",
"[",
"key",
".",
"kid",
"for",
"key",
"in",
"self",
".",
"_keys",
"if",
"key",
".",
"kid",
"!=",
"\"\"",
"]"
] | Return a list of key IDs. Note that this list may be shorter then
the list of keys. The reason might be that there are some keys with
no key ID.
:return: A list of all the key IDs that exists in this bundle | [
"Return",
"a",
"list",
"of",
"key",
"IDs",
".",
"Note",
"that",
"this",
"list",
"may",
"be",
"shorter",
"then",
"the",
"list",
"of",
"keys",
".",
"The",
"reason",
"might",
"be",
"that",
"there",
"are",
"some",
"keys",
"with",
"no",
"key",
"ID",
".",
... | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L496-L505 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | KeyBundle.mark_as_inactive | def mark_as_inactive(self, kid):
"""
Mark a specific key as inactive based on the keys KeyID
:param kid: The Key Identifier
"""
k = self.get_key_with_kid(kid)
k.inactive_since = time.time() | python | def mark_as_inactive(self, kid):
"""
Mark a specific key as inactive based on the keys KeyID
:param kid: The Key Identifier
"""
k = self.get_key_with_kid(kid)
k.inactive_since = time.time() | [
"def",
"mark_as_inactive",
"(",
"self",
",",
"kid",
")",
":",
"k",
"=",
"self",
".",
"get_key_with_kid",
"(",
"kid",
")",
"k",
".",
"inactive_since",
"=",
"time",
".",
"time",
"(",
")"
] | Mark a specific key as inactive based on the keys KeyID
:param kid: The Key Identifier | [
"Mark",
"a",
"specific",
"key",
"as",
"inactive",
"based",
"on",
"the",
"keys",
"KeyID",
":",
"param",
"kid",
":",
"The",
"Key",
"Identifier"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L507-L514 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | KeyBundle.remove_outdated | def remove_outdated(self, after, when=0):
"""
Remove keys that should not be available any more.
Outdated means that the key was marked as inactive at a time
that was longer ago then what is given in 'after'.
:param after: The length of time the key will remain in the KeyBundle
... | python | def remove_outdated(self, after, when=0):
"""
Remove keys that should not be available any more.
Outdated means that the key was marked as inactive at a time
that was longer ago then what is given in 'after'.
:param after: The length of time the key will remain in the KeyBundle
... | [
"def",
"remove_outdated",
"(",
"self",
",",
"after",
",",
"when",
"=",
"0",
")",
":",
"if",
"when",
":",
"now",
"=",
"when",
"else",
":",
"now",
"=",
"time",
".",
"time",
"(",
")",
"if",
"not",
"isinstance",
"(",
"after",
",",
"float",
")",
":",
... | Remove keys that should not be available any more.
Outdated means that the key was marked as inactive at a time
that was longer ago then what is given in 'after'.
:param after: The length of time the key will remain in the KeyBundle
before it should be removed.
:param when: ... | [
"Remove",
"keys",
"that",
"should",
"not",
"be",
"available",
"any",
"more",
".",
"Outdated",
"means",
"that",
"the",
"key",
"was",
"marked",
"as",
"inactive",
"at",
"a",
"time",
"that",
"was",
"longer",
"ago",
"then",
"what",
"is",
"given",
"in",
"after... | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L516-L544 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_bundle.py | KeyBundle.copy | def copy(self):
"""
Make deep copy of this KeyBundle
:return: The copy
"""
kb = KeyBundle()
kb._keys = self._keys[:]
kb.cache_time = self.cache_time
kb.verify_ssl = self.verify_ssl
if self.source:
kb.source = self.source
k... | python | def copy(self):
"""
Make deep copy of this KeyBundle
:return: The copy
"""
kb = KeyBundle()
kb._keys = self._keys[:]
kb.cache_time = self.cache_time
kb.verify_ssl = self.verify_ssl
if self.source:
kb.source = self.source
k... | [
"def",
"copy",
"(",
"self",
")",
":",
"kb",
"=",
"KeyBundle",
"(",
")",
"kb",
".",
"_keys",
"=",
"self",
".",
"_keys",
"[",
":",
"]",
"kb",
".",
"cache_time",
"=",
"self",
".",
"cache_time",
"kb",
".",
"verify_ssl",
"=",
"self",
".",
"verify_ssl",
... | Make deep copy of this KeyBundle
:return: The copy | [
"Make",
"deep",
"copy",
"of",
"this",
"KeyBundle"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_bundle.py#L549-L567 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/simple_jwt.py | SimpleJWT.unpack | def unpack(self, token, **kwargs):
"""
Unpacks a JWT into its parts and base64 decodes the parts
individually
:param token: The JWT
:param kwargs: A possible empty set of claims to verify the header
against.
"""
if isinstance(token, str):
... | python | def unpack(self, token, **kwargs):
"""
Unpacks a JWT into its parts and base64 decodes the parts
individually
:param token: The JWT
:param kwargs: A possible empty set of claims to verify the header
against.
"""
if isinstance(token, str):
... | [
"def",
"unpack",
"(",
"self",
",",
"token",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"isinstance",
"(",
"token",
",",
"str",
")",
":",
"try",
":",
"token",
"=",
"token",
".",
"encode",
"(",
"\"utf-8\"",
")",
"except",
"UnicodeDecodeError",
":",
"pass... | Unpacks a JWT into its parts and base64 decodes the parts
individually
:param token: The JWT
:param kwargs: A possible empty set of claims to verify the header
against. | [
"Unpacks",
"a",
"JWT",
"into",
"its",
"parts",
"and",
"base64",
"decodes",
"the",
"parts",
"individually"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/simple_jwt.py#L27-L60 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/simple_jwt.py | SimpleJWT.pack | def pack(self, parts=None, headers=None):
"""
Packs components into a JWT
:param parts: List of parts to pack
:param headers: The JWT headers
:return:
"""
if not headers:
if self.headers:
headers = self.headers
else:
... | python | def pack(self, parts=None, headers=None):
"""
Packs components into a JWT
:param parts: List of parts to pack
:param headers: The JWT headers
:return:
"""
if not headers:
if self.headers:
headers = self.headers
else:
... | [
"def",
"pack",
"(",
"self",
",",
"parts",
"=",
"None",
",",
"headers",
"=",
"None",
")",
":",
"if",
"not",
"headers",
":",
"if",
"self",
".",
"headers",
":",
"headers",
"=",
"self",
".",
"headers",
"else",
":",
"headers",
"=",
"{",
"'alg'",
":",
... | Packs components into a JWT
:param parts: List of parts to pack
:param headers: The JWT headers
:return: | [
"Packs",
"components",
"into",
"a",
"JWT"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/simple_jwt.py#L62-L85 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/simple_jwt.py | SimpleJWT.payload | def payload(self):
"""
Picks out the payload from the different parts of the signed/encrypted
JSON Web Token. If the content type is said to be 'jwt' deserialize the
payload into a Python object otherwise return as-is.
:return: The payload
"""
_msg = as_unicode(s... | python | def payload(self):
"""
Picks out the payload from the different parts of the signed/encrypted
JSON Web Token. If the content type is said to be 'jwt' deserialize the
payload into a Python object otherwise return as-is.
:return: The payload
"""
_msg = as_unicode(s... | [
"def",
"payload",
"(",
"self",
")",
":",
"_msg",
"=",
"as_unicode",
"(",
"self",
".",
"part",
"[",
"1",
"]",
")",
"# If not JSON web token assume JSON",
"if",
"\"cty\"",
"in",
"self",
".",
"headers",
"and",
"self",
".",
"headers",
"[",
"\"cty\"",
"]",
".... | Picks out the payload from the different parts of the signed/encrypted
JSON Web Token. If the content type is said to be 'jwt' deserialize the
payload into a Python object otherwise return as-is.
:return: The payload | [
"Picks",
"out",
"the",
"payload",
"from",
"the",
"different",
"parts",
"of",
"the",
"signed",
"/",
"encrypted",
"JSON",
"Web",
"Token",
".",
"If",
"the",
"content",
"type",
"is",
"said",
"to",
"be",
"jwt",
"deserialize",
"the",
"payload",
"into",
"a",
"P... | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/simple_jwt.py#L87-L106 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/simple_jwt.py | SimpleJWT.verify_header | def verify_header(self, key, val):
"""
Check that a particular header claim is present and has a specific value
:param key: The claim
:param val: The value of the claim
:raises: KeyError if the claim is not present in the header
:return: True if the claim exists in the h... | python | def verify_header(self, key, val):
"""
Check that a particular header claim is present and has a specific value
:param key: The claim
:param val: The value of the claim
:raises: KeyError if the claim is not present in the header
:return: True if the claim exists in the h... | [
"def",
"verify_header",
"(",
"self",
",",
"key",
",",
"val",
")",
":",
"if",
"isinstance",
"(",
"val",
",",
"list",
")",
":",
"if",
"self",
".",
"headers",
"[",
"key",
"]",
"in",
"val",
":",
"return",
"True",
"else",
":",
"return",
"False",
"else",... | Check that a particular header claim is present and has a specific value
:param key: The claim
:param val: The value of the claim
:raises: KeyError if the claim is not present in the header
:return: True if the claim exists in the header and has the prescribed
value | [
"Check",
"that",
"a",
"particular",
"header",
"claim",
"is",
"present",
"and",
"has",
"a",
"specific",
"value"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/simple_jwt.py#L108-L128 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/simple_jwt.py | SimpleJWT.verify_headers | def verify_headers(self, check_presence=True, **kwargs):
"""
Check that a set of particular header claim are present and has
specific values
:param kwargs: The claim/value sets as a dictionary
:return: True if the claim that appears in the header has the
prescribed v... | python | def verify_headers(self, check_presence=True, **kwargs):
"""
Check that a set of particular header claim are present and has
specific values
:param kwargs: The claim/value sets as a dictionary
:return: True if the claim that appears in the header has the
prescribed v... | [
"def",
"verify_headers",
"(",
"self",
",",
"check_presence",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"key",
",",
"val",
"in",
"kwargs",
".",
"items",
"(",
")",
":",
"try",
":",
"_ok",
"=",
"self",
".",
"verify_header",
"(",
"key",
",... | Check that a set of particular header claim are present and has
specific values
:param kwargs: The claim/value sets as a dictionary
:return: True if the claim that appears in the header has the
prescribed values. If a claim is not present in the header and
check_presence... | [
"Check",
"that",
"a",
"set",
"of",
"particular",
"header",
"claim",
"are",
"present",
"and",
"has",
"specific",
"values"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/simple_jwt.py#L130-L151 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jws/hmac.py | HMACSigner.sign | def sign(self, msg, key):
"""
Create a signature over a message as defined in RFC7515 using a
symmetric key
:param msg: The message
:param key: The key
:return: A signature
"""
h = hmac.HMAC(key, self.algorithm(), default_backend())
h.update(msg)
... | python | def sign(self, msg, key):
"""
Create a signature over a message as defined in RFC7515 using a
symmetric key
:param msg: The message
:param key: The key
:return: A signature
"""
h = hmac.HMAC(key, self.algorithm(), default_backend())
h.update(msg)
... | [
"def",
"sign",
"(",
"self",
",",
"msg",
",",
"key",
")",
":",
"h",
"=",
"hmac",
".",
"HMAC",
"(",
"key",
",",
"self",
".",
"algorithm",
"(",
")",
",",
"default_backend",
"(",
")",
")",
"h",
".",
"update",
"(",
"msg",
")",
"return",
"h",
".",
... | Create a signature over a message as defined in RFC7515 using a
symmetric key
:param msg: The message
:param key: The key
:return: A signature | [
"Create",
"a",
"signature",
"over",
"a",
"message",
"as",
"defined",
"in",
"RFC7515",
"using",
"a",
"symmetric",
"key"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jws/hmac.py#L23-L34 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jws/hmac.py | HMACSigner.verify | def verify(self, msg, sig, key):
"""
Verifies whether sig is the correct message authentication code of data.
:param msg: The data
:param sig: The message authentication code to verify against data.
:param key: The key to use
:return: Returns true if the mac was valid ot... | python | def verify(self, msg, sig, key):
"""
Verifies whether sig is the correct message authentication code of data.
:param msg: The data
:param sig: The message authentication code to verify against data.
:param key: The key to use
:return: Returns true if the mac was valid ot... | [
"def",
"verify",
"(",
"self",
",",
"msg",
",",
"sig",
",",
"key",
")",
":",
"try",
":",
"h",
"=",
"hmac",
".",
"HMAC",
"(",
"key",
",",
"self",
".",
"algorithm",
"(",
")",
",",
"default_backend",
"(",
")",
")",
"h",
".",
"update",
"(",
"msg",
... | Verifies whether sig is the correct message authentication code of data.
:param msg: The data
:param sig: The message authentication code to verify against data.
:param key: The key to use
:return: Returns true if the mac was valid otherwise it will raise an
Exception. | [
"Verifies",
"whether",
"sig",
"is",
"the",
"correct",
"message",
"authentication",
"code",
"of",
"data",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jws/hmac.py#L36-L52 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/tools/keygen.py | main | def main():
""" Main function"""
parser = argparse.ArgumentParser(description='JSON Web Key (JWK) Generator')
parser.add_argument('--kty',
dest='kty',
metavar='type',
help='Key type',
required=True)
parser.a... | python | def main():
""" Main function"""
parser = argparse.ArgumentParser(description='JSON Web Key (JWK) Generator')
parser.add_argument('--kty',
dest='kty',
metavar='type',
help='Key type',
required=True)
parser.a... | [
"def",
"main",
"(",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"'JSON Web Key (JWK) Generator'",
")",
"parser",
".",
"add_argument",
"(",
"'--kty'",
",",
"dest",
"=",
"'kty'",
",",
"metavar",
"=",
"'type'",
",",
"hel... | Main function | [
"Main",
"function"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/tools/keygen.py#L22-L74 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/jwk.py | ensure_ec_params | def ensure_ec_params(jwk_dict, private):
"""Ensure all required EC parameters are present in dictionary"""
provided = frozenset(jwk_dict.keys())
if private is not None and private:
required = EC_PUBLIC_REQUIRED | EC_PRIVATE_REQUIRED
else:
required = EC_PUBLIC_REQUIRED
return ensure_p... | python | def ensure_ec_params(jwk_dict, private):
"""Ensure all required EC parameters are present in dictionary"""
provided = frozenset(jwk_dict.keys())
if private is not None and private:
required = EC_PUBLIC_REQUIRED | EC_PRIVATE_REQUIRED
else:
required = EC_PUBLIC_REQUIRED
return ensure_p... | [
"def",
"ensure_ec_params",
"(",
"jwk_dict",
",",
"private",
")",
":",
"provided",
"=",
"frozenset",
"(",
"jwk_dict",
".",
"keys",
"(",
")",
")",
"if",
"private",
"is",
"not",
"None",
"and",
"private",
":",
"required",
"=",
"EC_PUBLIC_REQUIRED",
"|",
"EC_PR... | Ensure all required EC parameters are present in dictionary | [
"Ensure",
"all",
"required",
"EC",
"parameters",
"are",
"present",
"in",
"dictionary"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/jwk.py#L35-L42 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/jwk.py | ensure_rsa_params | def ensure_rsa_params(jwk_dict, private):
"""Ensure all required RSA parameters are present in dictionary"""
provided = frozenset(jwk_dict.keys())
if private is not None and private:
required = RSA_PUBLIC_REQUIRED | RSA_PRIVATE_REQUIRED
else:
required = RSA_PUBLIC_REQUIRED
return ens... | python | def ensure_rsa_params(jwk_dict, private):
"""Ensure all required RSA parameters are present in dictionary"""
provided = frozenset(jwk_dict.keys())
if private is not None and private:
required = RSA_PUBLIC_REQUIRED | RSA_PRIVATE_REQUIRED
else:
required = RSA_PUBLIC_REQUIRED
return ens... | [
"def",
"ensure_rsa_params",
"(",
"jwk_dict",
",",
"private",
")",
":",
"provided",
"=",
"frozenset",
"(",
"jwk_dict",
".",
"keys",
"(",
")",
")",
"if",
"private",
"is",
"not",
"None",
"and",
"private",
":",
"required",
"=",
"RSA_PUBLIC_REQUIRED",
"|",
"RSA... | Ensure all required RSA parameters are present in dictionary | [
"Ensure",
"all",
"required",
"RSA",
"parameters",
"are",
"present",
"in",
"dictionary"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/jwk.py#L45-L52 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/jwk.py | ensure_params | def ensure_params(kty, provided, required):
"""Ensure all required parameters are present in dictionary"""
if not required <= provided:
missing = required - provided
raise MissingValue('Missing properties for kty={}, {}'.format(kty, str(list(missing)))) | python | def ensure_params(kty, provided, required):
"""Ensure all required parameters are present in dictionary"""
if not required <= provided:
missing = required - provided
raise MissingValue('Missing properties for kty={}, {}'.format(kty, str(list(missing)))) | [
"def",
"ensure_params",
"(",
"kty",
",",
"provided",
",",
"required",
")",
":",
"if",
"not",
"required",
"<=",
"provided",
":",
"missing",
"=",
"required",
"-",
"provided",
"raise",
"MissingValue",
"(",
"'Missing properties for kty={}, {}'",
".",
"format",
"(",
... | Ensure all required parameters are present in dictionary | [
"Ensure",
"all",
"required",
"parameters",
"are",
"present",
"in",
"dictionary"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/jwk.py#L55-L59 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/jwk.py | key_from_jwk_dict | def key_from_jwk_dict(jwk_dict, private=None):
"""Load JWK from dictionary
:param jwk_dict: Dictionary representing a JWK
"""
# uncouple from the original item
_jwk_dict = copy.copy(jwk_dict)
if 'kty' not in _jwk_dict:
raise MissingValue('kty missing')
if _jwk_dict['kty'] == 'EC'... | python | def key_from_jwk_dict(jwk_dict, private=None):
"""Load JWK from dictionary
:param jwk_dict: Dictionary representing a JWK
"""
# uncouple from the original item
_jwk_dict = copy.copy(jwk_dict)
if 'kty' not in _jwk_dict:
raise MissingValue('kty missing')
if _jwk_dict['kty'] == 'EC'... | [
"def",
"key_from_jwk_dict",
"(",
"jwk_dict",
",",
"private",
"=",
"None",
")",
":",
"# uncouple from the original item",
"_jwk_dict",
"=",
"copy",
".",
"copy",
"(",
"jwk_dict",
")",
"if",
"'kty'",
"not",
"in",
"_jwk_dict",
":",
"raise",
"MissingValue",
"(",
"'... | Load JWK from dictionary
:param jwk_dict: Dictionary representing a JWK | [
"Load",
"JWK",
"from",
"dictionary"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/jwk.py#L62-L153 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/jwk.py | jwk_wrap | def jwk_wrap(key, use="", kid=""):
"""
Instantiate a Key instance with the given key
:param key: The keys to wrap
:param use: What the key are expected to be use for
:param kid: A key id
:return: The Key instance
"""
if isinstance(key, rsa.RSAPublicKey) or isinstance(key, rsa.RSAPrivate... | python | def jwk_wrap(key, use="", kid=""):
"""
Instantiate a Key instance with the given key
:param key: The keys to wrap
:param use: What the key are expected to be use for
:param kid: A key id
:return: The Key instance
"""
if isinstance(key, rsa.RSAPublicKey) or isinstance(key, rsa.RSAPrivate... | [
"def",
"jwk_wrap",
"(",
"key",
",",
"use",
"=",
"\"\"",
",",
"kid",
"=",
"\"\"",
")",
":",
"if",
"isinstance",
"(",
"key",
",",
"rsa",
".",
"RSAPublicKey",
")",
"or",
"isinstance",
"(",
"key",
",",
"rsa",
".",
"RSAPrivateKey",
")",
":",
"kspec",
"=... | Instantiate a Key instance with the given key
:param key: The keys to wrap
:param use: What the key are expected to be use for
:param kid: A key id
:return: The Key instance | [
"Instantiate",
"a",
"Key",
"instance",
"with",
"the",
"given",
"key"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/jwk.py#L156-L175 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | build_keyjar | def build_keyjar(key_conf, kid_template="", keyjar=None, owner=''):
"""
Builds a :py:class:`oidcmsg.key_jar.KeyJar` instance or adds keys to
an existing KeyJar based on a key specification.
An example of such a specification::
keys = [
{"type": "RSA", "key": "cp_keys/key.pem", ... | python | def build_keyjar(key_conf, kid_template="", keyjar=None, owner=''):
"""
Builds a :py:class:`oidcmsg.key_jar.KeyJar` instance or adds keys to
an existing KeyJar based on a key specification.
An example of such a specification::
keys = [
{"type": "RSA", "key": "cp_keys/key.pem", ... | [
"def",
"build_keyjar",
"(",
"key_conf",
",",
"kid_template",
"=",
"\"\"",
",",
"keyjar",
"=",
"None",
",",
"owner",
"=",
"''",
")",
":",
"if",
"keyjar",
"is",
"None",
":",
"keyjar",
"=",
"KeyJar",
"(",
")",
"tot_kb",
"=",
"build_key_bundle",
"(",
"key_... | Builds a :py:class:`oidcmsg.key_jar.KeyJar` instance or adds keys to
an existing KeyJar based on a key specification.
An example of such a specification::
keys = [
{"type": "RSA", "key": "cp_keys/key.pem", "use": ["enc", "sig"]},
{"type": "EC", "crv": "P-256", "use": ["sig"... | [
"Builds",
"a",
":",
"py",
":",
"class",
":",
"oidcmsg",
".",
"key_jar",
".",
"KeyJar",
"instance",
"or",
"adds",
"keys",
"to",
"an",
"existing",
"KeyJar",
"based",
"on",
"a",
"key",
"specification",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L647-L695 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | update_keyjar | def update_keyjar(keyjar):
"""
Go through the whole key jar, key bundle by key bundle and update them one
by one.
:param keyjar: The key jar to update
"""
for iss, kbl in keyjar.items():
for kb in kbl:
kb.update() | python | def update_keyjar(keyjar):
"""
Go through the whole key jar, key bundle by key bundle and update them one
by one.
:param keyjar: The key jar to update
"""
for iss, kbl in keyjar.items():
for kb in kbl:
kb.update() | [
"def",
"update_keyjar",
"(",
"keyjar",
")",
":",
"for",
"iss",
",",
"kbl",
"in",
"keyjar",
".",
"items",
"(",
")",
":",
"for",
"kb",
"in",
"kbl",
":",
"kb",
".",
"update",
"(",
")"
] | Go through the whole key jar, key bundle by key bundle and update them one
by one.
:param keyjar: The key jar to update | [
"Go",
"through",
"the",
"whole",
"key",
"jar",
"key",
"bundle",
"by",
"key",
"bundle",
"and",
"update",
"them",
"one",
"by",
"one",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L698-L707 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | key_summary | def key_summary(keyjar, issuer):
"""
Return a text representation of the keyjar.
:param keyjar: A :py:class:`oidcmsg.key_jar.KeyJar` instance
:param issuer: Which key owner that we are looking at
:return: A text representation of the keys
"""
try:
kbl = keyjar[issuer]
except Key... | python | def key_summary(keyjar, issuer):
"""
Return a text representation of the keyjar.
:param keyjar: A :py:class:`oidcmsg.key_jar.KeyJar` instance
:param issuer: Which key owner that we are looking at
:return: A text representation of the keys
"""
try:
kbl = keyjar[issuer]
except Key... | [
"def",
"key_summary",
"(",
"keyjar",
",",
"issuer",
")",
":",
"try",
":",
"kbl",
"=",
"keyjar",
"[",
"issuer",
"]",
"except",
"KeyError",
":",
"return",
"''",
"else",
":",
"key_list",
"=",
"[",
"]",
"for",
"kb",
"in",
"kbl",
":",
"for",
"key",
"in"... | Return a text representation of the keyjar.
:param keyjar: A :py:class:`oidcmsg.key_jar.KeyJar` instance
:param issuer: Which key owner that we are looking at
:return: A text representation of the keys | [
"Return",
"a",
"text",
"representation",
"of",
"the",
"keyjar",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L710-L732 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | init_key_jar | def init_key_jar(public_path='', private_path='', key_defs='', owner='',
read_only=True):
"""
A number of cases here:
1. A private path is given
a. The file exists and a JWKS is found there.
From that JWKS a KeyJar instance is built.
b.
If the private pat... | python | def init_key_jar(public_path='', private_path='', key_defs='', owner='',
read_only=True):
"""
A number of cases here:
1. A private path is given
a. The file exists and a JWKS is found there.
From that JWKS a KeyJar instance is built.
b.
If the private pat... | [
"def",
"init_key_jar",
"(",
"public_path",
"=",
"''",
",",
"private_path",
"=",
"''",
",",
"key_defs",
"=",
"''",
",",
"owner",
"=",
"''",
",",
"read_only",
"=",
"True",
")",
":",
"if",
"private_path",
":",
"if",
"os",
".",
"path",
".",
"isfile",
"("... | A number of cases here:
1. A private path is given
a. The file exists and a JWKS is found there.
From that JWKS a KeyJar instance is built.
b.
If the private path file doesn't exit the key definitions are
used to build a KeyJar instance. A JWKS with the private keys are... | [
"A",
"number",
"of",
"cases",
"here",
":"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L735-L848 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | KeyJar.add_url | def add_url(self, issuer, url, **kwargs):
"""
Add a set of keys by url. This method will create a
:py:class:`oidcmsg.key_bundle.KeyBundle` instance with the
url as source specification. If no file format is given it's assumed
that what's on the other side is a JWKS.
... | python | def add_url(self, issuer, url, **kwargs):
"""
Add a set of keys by url. This method will create a
:py:class:`oidcmsg.key_bundle.KeyBundle` instance with the
url as source specification. If no file format is given it's assumed
that what's on the other side is a JWKS.
... | [
"def",
"add_url",
"(",
"self",
",",
"issuer",
",",
"url",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"url",
":",
"raise",
"KeyError",
"(",
"\"No url given\"",
")",
"if",
"\"/localhost:\"",
"in",
"url",
"or",
"\"/localhost/\"",
"in",
"url",
":",
"k... | Add a set of keys by url. This method will create a
:py:class:`oidcmsg.key_bundle.KeyBundle` instance with the
url as source specification. If no file format is given it's assumed
that what's on the other side is a JWKS.
:param issuer: Who issued the keys
:param url: Wh... | [
"Add",
"a",
"set",
"of",
"keys",
"by",
"url",
".",
"This",
"method",
"will",
"create",
"a",
":",
"py",
":",
"class",
":",
"oidcmsg",
".",
"key_bundle",
".",
"KeyBundle",
"instance",
"with",
"the",
"url",
"as",
"source",
"specification",
".",
"If",
"no"... | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L59-L85 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | KeyJar.add_symmetric | def add_symmetric(self, issuer, key, usage=None):
"""
Add a symmetric key. This is done by wrapping it in a key bundle
cloak since KeyJar does not handle keys directly but only through
key bundles.
:param issuer: Owner of the key
:param key: The key
:pa... | python | def add_symmetric(self, issuer, key, usage=None):
"""
Add a symmetric key. This is done by wrapping it in a key bundle
cloak since KeyJar does not handle keys directly but only through
key bundles.
:param issuer: Owner of the key
:param key: The key
:pa... | [
"def",
"add_symmetric",
"(",
"self",
",",
"issuer",
",",
"key",
",",
"usage",
"=",
"None",
")",
":",
"if",
"issuer",
"not",
"in",
"self",
".",
"issuer_keys",
":",
"self",
".",
"issuer_keys",
"[",
"issuer",
"]",
"=",
"[",
"]",
"if",
"usage",
"is",
"... | Add a symmetric key. This is done by wrapping it in a key bundle
cloak since KeyJar does not handle keys directly but only through
key bundles.
:param issuer: Owner of the key
:param key: The key
:param usage: What the key can be used for signing/signature
... | [
"Add",
"a",
"symmetric",
"key",
".",
"This",
"is",
"done",
"by",
"wrapping",
"it",
"in",
"a",
"key",
"bundle",
"cloak",
"since",
"KeyJar",
"does",
"not",
"handle",
"keys",
"directly",
"but",
"only",
"through",
"key",
"bundles",
".",
":",
"param",
"issuer... | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L87-L109 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | KeyJar.add_kb | def add_kb(self, issuer, kb):
"""
Add a key bundle and bind it to an identifier
:param issuer: Owner of the keys in the key bundle
:param kb: A :py:class:`oidcmsg.key_bundle.KeyBundle` instance
"""
try:
self.issuer_keys[issuer].append(kb)
exce... | python | def add_kb(self, issuer, kb):
"""
Add a key bundle and bind it to an identifier
:param issuer: Owner of the keys in the key bundle
:param kb: A :py:class:`oidcmsg.key_bundle.KeyBundle` instance
"""
try:
self.issuer_keys[issuer].append(kb)
exce... | [
"def",
"add_kb",
"(",
"self",
",",
"issuer",
",",
"kb",
")",
":",
"try",
":",
"self",
".",
"issuer_keys",
"[",
"issuer",
"]",
".",
"append",
"(",
"kb",
")",
"except",
"KeyError",
":",
"self",
".",
"issuer_keys",
"[",
"issuer",
"]",
"=",
"[",
"kb",
... | Add a key bundle and bind it to an identifier
:param issuer: Owner of the keys in the key bundle
:param kb: A :py:class:`oidcmsg.key_bundle.KeyBundle` instance | [
"Add",
"a",
"key",
"bundle",
"and",
"bind",
"it",
"to",
"an",
"identifier",
":",
"param",
"issuer",
":",
"Owner",
"of",
"the",
"keys",
"in",
"the",
"key",
"bundle",
":",
"param",
"kb",
":",
"A",
":",
"py",
":",
"class",
":",
"oidcmsg",
".",
"key_bu... | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L111-L121 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | KeyJar.get | def get(self, key_use, key_type="", owner="", kid=None, **kwargs):
"""
Get all keys that matches a set of search criteria
:param key_use: A key useful for this usage (enc, dec, sig, ver)
:param key_type: Type of key (rsa, ec, oct, ..)
:param owner: Who is the owner of the keys, ... | python | def get(self, key_use, key_type="", owner="", kid=None, **kwargs):
"""
Get all keys that matches a set of search criteria
:param key_use: A key useful for this usage (enc, dec, sig, ver)
:param key_type: Type of key (rsa, ec, oct, ..)
:param owner: Who is the owner of the keys, ... | [
"def",
"get",
"(",
"self",
",",
"key_use",
",",
"key_type",
"=",
"\"\"",
",",
"owner",
"=",
"\"\"",
",",
"kid",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"key_use",
"in",
"[",
"\"dec\"",
",",
"\"enc\"",
"]",
":",
"use",
"=",
"\"enc\""... | Get all keys that matches a set of search criteria
:param key_use: A key useful for this usage (enc, dec, sig, ver)
:param key_type: Type of key (rsa, ec, oct, ..)
:param owner: Who is the owner of the keys, "" == me (default)
:param kid: A Key Identifier
:return: A possibly emp... | [
"Get",
"all",
"keys",
"that",
"matches",
"a",
"set",
"of",
"search",
"criteria"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L148-L230 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | KeyJar.get_signing_key | def get_signing_key(self, key_type="", owner="", kid=None, **kwargs):
"""
Shortcut to use for signing keys only.
:param key_type: Type of key (rsa, ec, oct, ..)
:param owner: Who is the owner of the keys, "" == me (default)
:param kid: A Key Identifier
:param kwargs: Ext... | python | def get_signing_key(self, key_type="", owner="", kid=None, **kwargs):
"""
Shortcut to use for signing keys only.
:param key_type: Type of key (rsa, ec, oct, ..)
:param owner: Who is the owner of the keys, "" == me (default)
:param kid: A Key Identifier
:param kwargs: Ext... | [
"def",
"get_signing_key",
"(",
"self",
",",
"key_type",
"=",
"\"\"",
",",
"owner",
"=",
"\"\"",
",",
"kid",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"get",
"(",
"\"sig\"",
",",
"key_type",
",",
"owner",
",",
"kid",
","... | Shortcut to use for signing keys only.
:param key_type: Type of key (rsa, ec, oct, ..)
:param owner: Who is the owner of the keys, "" == me (default)
:param kid: A Key Identifier
:param kwargs: Extra key word arguments
:return: A possibly empty list of keys | [
"Shortcut",
"to",
"use",
"for",
"signing",
"keys",
"only",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L232-L242 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | KeyJar.keys_by_alg_and_usage | def keys_by_alg_and_usage(self, issuer, alg, usage):
"""
Find all keys that can be used for a specific crypto algorithm and
usage by key owner.
:param issuer: Key owner
:param alg: a crypto algorithm
:param usage: What the key should be used for
:return: A possib... | python | def keys_by_alg_and_usage(self, issuer, alg, usage):
"""
Find all keys that can be used for a specific crypto algorithm and
usage by key owner.
:param issuer: Key owner
:param alg: a crypto algorithm
:param usage: What the key should be used for
:return: A possib... | [
"def",
"keys_by_alg_and_usage",
"(",
"self",
",",
"issuer",
",",
"alg",
",",
"usage",
")",
":",
"if",
"usage",
"in",
"[",
"\"sig\"",
",",
"\"ver\"",
"]",
":",
"ktype",
"=",
"jws_alg2keytype",
"(",
"alg",
")",
"else",
":",
"ktype",
"=",
"jwe_alg2keytype",... | Find all keys that can be used for a specific crypto algorithm and
usage by key owner.
:param issuer: Key owner
:param alg: a crypto algorithm
:param usage: What the key should be used for
:return: A possibly empty list of keys | [
"Find",
"all",
"keys",
"that",
"can",
"be",
"used",
"for",
"a",
"specific",
"crypto",
"algorithm",
"and",
"usage",
"by",
"key",
"owner",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L253-L268 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | KeyJar.get_issuer_keys | def get_issuer_keys(self, issuer):
"""
Get all the keys that belong to an entity.
:param issuer: The entity ID
:return: A possibly empty list of keys
"""
res = []
for kbl in self.issuer_keys[issuer]:
res.extend(kbl.keys())
return res | python | def get_issuer_keys(self, issuer):
"""
Get all the keys that belong to an entity.
:param issuer: The entity ID
:return: A possibly empty list of keys
"""
res = []
for kbl in self.issuer_keys[issuer]:
res.extend(kbl.keys())
return res | [
"def",
"get_issuer_keys",
"(",
"self",
",",
"issuer",
")",
":",
"res",
"=",
"[",
"]",
"for",
"kbl",
"in",
"self",
".",
"issuer_keys",
"[",
"issuer",
"]",
":",
"res",
".",
"extend",
"(",
"kbl",
".",
"keys",
"(",
")",
")",
"return",
"res"
] | Get all the keys that belong to an entity.
:param issuer: The entity ID
:return: A possibly empty list of keys | [
"Get",
"all",
"the",
"keys",
"that",
"belong",
"to",
"an",
"entity",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L270-L280 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | KeyJar.match_owner | def match_owner(self, url):
"""
Finds the first entity, with keys in the key jar, with an
identifier that matches the given URL. The match is a leading
substring match.
:param url: A URL
:return: An issue entity ID that exists in the Key jar
"""
for owner... | python | def match_owner(self, url):
"""
Finds the first entity, with keys in the key jar, with an
identifier that matches the given URL. The match is a leading
substring match.
:param url: A URL
:return: An issue entity ID that exists in the Key jar
"""
for owner... | [
"def",
"match_owner",
"(",
"self",
",",
"url",
")",
":",
"for",
"owner",
"in",
"self",
".",
"issuer_keys",
".",
"keys",
"(",
")",
":",
"if",
"owner",
".",
"startswith",
"(",
"url",
")",
":",
"return",
"owner",
"raise",
"KeyError",
"(",
"\"No keys for '... | Finds the first entity, with keys in the key jar, with an
identifier that matches the given URL. The match is a leading
substring match.
:param url: A URL
:return: An issue entity ID that exists in the Key jar | [
"Finds",
"the",
"first",
"entity",
"with",
"keys",
"in",
"the",
"key",
"jar",
"with",
"an",
"identifier",
"that",
"matches",
"the",
"given",
"URL",
".",
"The",
"match",
"is",
"a",
"leading",
"substring",
"match",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L311-L324 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | KeyJar.load_keys | def load_keys(self, issuer, jwks_uri='', jwks=None, replace=False):
"""
Fetch keys from another server
:param jwks_uri: A URL pointing to a site that will return a JWKS
:param jwks: A dictionary representation of a JWKS
:param issuer: The provider URL
:param replace: If ... | python | def load_keys(self, issuer, jwks_uri='', jwks=None, replace=False):
"""
Fetch keys from another server
:param jwks_uri: A URL pointing to a site that will return a JWKS
:param jwks: A dictionary representation of a JWKS
:param issuer: The provider URL
:param replace: If ... | [
"def",
"load_keys",
"(",
"self",
",",
"issuer",
",",
"jwks_uri",
"=",
"''",
",",
"jwks",
"=",
"None",
",",
"replace",
"=",
"False",
")",
":",
"logger",
".",
"debug",
"(",
"\"Initiating key bundle for issuer: %s\"",
"%",
"issuer",
")",
"if",
"replace",
"or"... | Fetch keys from another server
:param jwks_uri: A URL pointing to a site that will return a JWKS
:param jwks: A dictionary representation of a JWKS
:param issuer: The provider URL
:param replace: If all previously gathered keys from this provider
should be replace.
:... | [
"Fetch",
"keys",
"from",
"another",
"server"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L335-L357 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | KeyJar.find | def find(self, source, issuer):
"""
Find a key bundle based on the source of the keys
:param source: A source url
:param issuer: The issuer of keys
:return: A :py:class:`oidcmsg.key_bundle.KeyBundle` instance or None
"""
try:
for kb in self.issuer_key... | python | def find(self, source, issuer):
"""
Find a key bundle based on the source of the keys
:param source: A source url
:param issuer: The issuer of keys
:return: A :py:class:`oidcmsg.key_bundle.KeyBundle` instance or None
"""
try:
for kb in self.issuer_key... | [
"def",
"find",
"(",
"self",
",",
"source",
",",
"issuer",
")",
":",
"try",
":",
"for",
"kb",
"in",
"self",
".",
"issuer_keys",
"[",
"issuer",
"]",
":",
"if",
"kb",
".",
"source",
"==",
"source",
":",
"return",
"kb",
"except",
"KeyError",
":",
"retu... | Find a key bundle based on the source of the keys
:param source: A source url
:param issuer: The issuer of keys
:return: A :py:class:`oidcmsg.key_bundle.KeyBundle` instance or None | [
"Find",
"a",
"key",
"bundle",
"based",
"on",
"the",
"source",
"of",
"the",
"keys"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L359-L374 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | KeyJar.export_jwks | def export_jwks(self, private=False, issuer=""):
"""
Produces a dictionary that later can be easily mapped into a
JSON string representing a JWKS.
:param private: Whether it should be the private keys or the public
:param issuer: The entity ID.
:return: A dictio... | python | def export_jwks(self, private=False, issuer=""):
"""
Produces a dictionary that later can be easily mapped into a
JSON string representing a JWKS.
:param private: Whether it should be the private keys or the public
:param issuer: The entity ID.
:return: A dictio... | [
"def",
"export_jwks",
"(",
"self",
",",
"private",
"=",
"False",
",",
"issuer",
"=",
"\"\"",
")",
":",
"keys",
"=",
"[",
"]",
"for",
"kb",
"in",
"self",
".",
"issuer_keys",
"[",
"issuer",
"]",
":",
"keys",
".",
"extend",
"(",
"[",
"k",
".",
"seri... | Produces a dictionary that later can be easily mapped into a
JSON string representing a JWKS.
:param private: Whether it should be the private keys or the public
:param issuer: The entity ID.
:return: A dictionary with one key: 'keys' | [
"Produces",
"a",
"dictionary",
"that",
"later",
"can",
"be",
"easily",
"mapped",
"into",
"a",
"JSON",
"string",
"representing",
"a",
"JWKS",
".",
":",
"param",
"private",
":",
"Whether",
"it",
"should",
"be",
"the",
"private",
"keys",
"or",
"the",
"public"... | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L376-L389 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | KeyJar.export_jwks_as_json | def export_jwks_as_json(self, private=False, issuer=""):
"""
Export a JWKS as a JSON document.
:param private: Whether it should be the private keys or the public
:param issuer: The entity ID.
:return: A JSON representation of a JWKS
"""
return json.dumps(self.ex... | python | def export_jwks_as_json(self, private=False, issuer=""):
"""
Export a JWKS as a JSON document.
:param private: Whether it should be the private keys or the public
:param issuer: The entity ID.
:return: A JSON representation of a JWKS
"""
return json.dumps(self.ex... | [
"def",
"export_jwks_as_json",
"(",
"self",
",",
"private",
"=",
"False",
",",
"issuer",
"=",
"\"\"",
")",
":",
"return",
"json",
".",
"dumps",
"(",
"self",
".",
"export_jwks",
"(",
"private",
",",
"issuer",
")",
")"
] | Export a JWKS as a JSON document.
:param private: Whether it should be the private keys or the public
:param issuer: The entity ID.
:return: A JSON representation of a JWKS | [
"Export",
"a",
"JWKS",
"as",
"a",
"JSON",
"document",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L391-L399 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | KeyJar.import_jwks | def import_jwks(self, jwks, issuer):
"""
Imports all the keys that are represented in a JWKS
:param jwks: Dictionary representation of a JWKS
:param issuer: Who 'owns' the JWKS
"""
try:
_keys = jwks["keys"]
except KeyError:
raise ValueErro... | python | def import_jwks(self, jwks, issuer):
"""
Imports all the keys that are represented in a JWKS
:param jwks: Dictionary representation of a JWKS
:param issuer: Who 'owns' the JWKS
"""
try:
_keys = jwks["keys"]
except KeyError:
raise ValueErro... | [
"def",
"import_jwks",
"(",
"self",
",",
"jwks",
",",
"issuer",
")",
":",
"try",
":",
"_keys",
"=",
"jwks",
"[",
"\"keys\"",
"]",
"except",
"KeyError",
":",
"raise",
"ValueError",
"(",
"'Not a proper JWKS'",
")",
"else",
":",
"try",
":",
"self",
".",
"i... | Imports all the keys that are represented in a JWKS
:param jwks: Dictionary representation of a JWKS
:param issuer: Who 'owns' the JWKS | [
"Imports",
"all",
"the",
"keys",
"that",
"are",
"represented",
"in",
"a",
"JWKS"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L401-L418 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | KeyJar.import_jwks_as_json | def import_jwks_as_json(self, jwks, issuer):
"""
Imports all the keys that are represented in a JWKS expressed as a
JSON object
:param jwks: JSON representation of a JWKS
:param issuer: Who 'owns' the JWKS
"""
return self.import_jwks(json.loads(jwks), issuer) | python | def import_jwks_as_json(self, jwks, issuer):
"""
Imports all the keys that are represented in a JWKS expressed as a
JSON object
:param jwks: JSON representation of a JWKS
:param issuer: Who 'owns' the JWKS
"""
return self.import_jwks(json.loads(jwks), issuer) | [
"def",
"import_jwks_as_json",
"(",
"self",
",",
"jwks",
",",
"issuer",
")",
":",
"return",
"self",
".",
"import_jwks",
"(",
"json",
".",
"loads",
"(",
"jwks",
")",
",",
"issuer",
")"
] | Imports all the keys that are represented in a JWKS expressed as a
JSON object
:param jwks: JSON representation of a JWKS
:param issuer: Who 'owns' the JWKS | [
"Imports",
"all",
"the",
"keys",
"that",
"are",
"represented",
"in",
"a",
"JWKS",
"expressed",
"as",
"a",
"JSON",
"object"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L420-L428 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | KeyJar.remove_outdated | def remove_outdated(self, when=0):
"""
Goes through the complete list of issuers and for each of them removes
outdated keys.
Outdated keys are keys that has been marked as inactive at a time that
is longer ago then some set number of seconds (when). If when=0 the
the base... | python | def remove_outdated(self, when=0):
"""
Goes through the complete list of issuers and for each of them removes
outdated keys.
Outdated keys are keys that has been marked as inactive at a time that
is longer ago then some set number of seconds (when). If when=0 the
the base... | [
"def",
"remove_outdated",
"(",
"self",
",",
"when",
"=",
"0",
")",
":",
"for",
"iss",
"in",
"list",
"(",
"self",
".",
"owners",
"(",
")",
")",
":",
"_kbl",
"=",
"[",
"]",
"for",
"kb",
"in",
"self",
".",
"issuer_keys",
"[",
"iss",
"]",
":",
"kb"... | Goes through the complete list of issuers and for each of them removes
outdated keys.
Outdated keys are keys that has been marked as inactive at a time that
is longer ago then some set number of seconds (when). If when=0 the
the base time is set to now.
The number of seconds a ca... | [
"Goes",
"through",
"the",
"complete",
"list",
"of",
"issuers",
"and",
"for",
"each",
"of",
"them",
"removes",
"outdated",
"keys",
".",
"Outdated",
"keys",
"are",
"keys",
"that",
"has",
"been",
"marked",
"as",
"inactive",
"at",
"a",
"time",
"that",
"is",
... | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L454-L475 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | KeyJar.get_jwt_decrypt_keys | def get_jwt_decrypt_keys(self, jwt, **kwargs):
"""
Get decryption keys from this keyjar based on information carried
in a JWE. These keys should be usable to decrypt an encrypted JWT.
:param jwt: A cryptojwt.jwt.JWT instance
:param kwargs: Other key word arguments
:retur... | python | def get_jwt_decrypt_keys(self, jwt, **kwargs):
"""
Get decryption keys from this keyjar based on information carried
in a JWE. These keys should be usable to decrypt an encrypted JWT.
:param jwt: A cryptojwt.jwt.JWT instance
:param kwargs: Other key word arguments
:retur... | [
"def",
"get_jwt_decrypt_keys",
"(",
"self",
",",
"jwt",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"_key_type",
"=",
"jwe_alg2keytype",
"(",
"jwt",
".",
"headers",
"[",
"'alg'",
"]",
")",
"except",
"KeyError",
":",
"_key_type",
"=",
"''",
"try",
":... | Get decryption keys from this keyjar based on information carried
in a JWE. These keys should be usable to decrypt an encrypted JWT.
:param jwt: A cryptojwt.jwt.JWT instance
:param kwargs: Other key word arguments
:return: list of usable keys | [
"Get",
"decryption",
"keys",
"from",
"this",
"keyjar",
"based",
"on",
"information",
"carried",
"in",
"a",
"JWE",
".",
"These",
"keys",
"should",
"be",
"usable",
"to",
"decrypt",
"an",
"encrypted",
"JWT",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L519-L563 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | KeyJar.get_jwt_verify_keys | def get_jwt_verify_keys(self, jwt, **kwargs):
"""
Get keys from this key jar based on information in a JWS. These keys
should be usable to verify the signed JWT.
:param jwt: A cryptojwt.jwt.JWT instance
:param kwargs: Other key word arguments
:return: list of usable keys... | python | def get_jwt_verify_keys(self, jwt, **kwargs):
"""
Get keys from this key jar based on information in a JWS. These keys
should be usable to verify the signed JWT.
:param jwt: A cryptojwt.jwt.JWT instance
:param kwargs: Other key word arguments
:return: list of usable keys... | [
"def",
"get_jwt_verify_keys",
"(",
"self",
",",
"jwt",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"allow_missing_kid",
"=",
"kwargs",
"[",
"'allow_missing_kid'",
"]",
"except",
"KeyError",
":",
"allow_missing_kid",
"=",
"False",
"try",
":",
"_key_type",
... | Get keys from this key jar based on information in a JWS. These keys
should be usable to verify the signed JWT.
:param jwt: A cryptojwt.jwt.JWT instance
:param kwargs: Other key word arguments
:return: list of usable keys | [
"Get",
"keys",
"from",
"this",
"key",
"jar",
"based",
"on",
"information",
"in",
"a",
"JWS",
".",
"These",
"keys",
"should",
"be",
"usable",
"to",
"verify",
"the",
"signed",
"JWT",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L565-L628 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/key_jar.py | KeyJar.copy | def copy(self):
"""
Make deep copy of this key jar.
:return: A :py:class:`oidcmsg.key_jar.KeyJar` instance
"""
kj = KeyJar()
for issuer in self.owners():
kj[issuer] = [kb.copy() for kb in self[issuer]]
kj.verify_ssl = self.verify_ssl
return k... | python | def copy(self):
"""
Make deep copy of this key jar.
:return: A :py:class:`oidcmsg.key_jar.KeyJar` instance
"""
kj = KeyJar()
for issuer in self.owners():
kj[issuer] = [kb.copy() for kb in self[issuer]]
kj.verify_ssl = self.verify_ssl
return k... | [
"def",
"copy",
"(",
"self",
")",
":",
"kj",
"=",
"KeyJar",
"(",
")",
"for",
"issuer",
"in",
"self",
".",
"owners",
"(",
")",
":",
"kj",
"[",
"issuer",
"]",
"=",
"[",
"kb",
".",
"copy",
"(",
")",
"for",
"kb",
"in",
"self",
"[",
"issuer",
"]",
... | Make deep copy of this key jar.
:return: A :py:class:`oidcmsg.key_jar.KeyJar` instance | [
"Make",
"deep",
"copy",
"of",
"this",
"key",
"jar",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/key_jar.py#L630-L641 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwt.py | pick_key | def pick_key(keys, use, alg='', key_type='', kid=''):
"""
Based on given criteria pick out the keys that fulfill them from a
given set of keys.
:param keys: List of keys. These are :py:class:`cryptojwt.jwk.JWK`
instances.
:param use: What the key is going to be used for 'sig'/'enc'
:par... | python | def pick_key(keys, use, alg='', key_type='', kid=''):
"""
Based on given criteria pick out the keys that fulfill them from a
given set of keys.
:param keys: List of keys. These are :py:class:`cryptojwt.jwk.JWK`
instances.
:param use: What the key is going to be used for 'sig'/'enc'
:par... | [
"def",
"pick_key",
"(",
"keys",
",",
"use",
",",
"alg",
"=",
"''",
",",
"key_type",
"=",
"''",
",",
"kid",
"=",
"''",
")",
":",
"res",
"=",
"[",
"]",
"if",
"not",
"key_type",
":",
"if",
"use",
"==",
"'sig'",
":",
"key_type",
"=",
"jws_alg2keytype... | Based on given criteria pick out the keys that fulfill them from a
given set of keys.
:param keys: List of keys. These are :py:class:`cryptojwt.jwk.JWK`
instances.
:param use: What the key is going to be used for 'sig'/'enc'
:param alg: crypto algorithm
:param key_type: Type of key 'rsa'/'e... | [
"Based",
"on",
"given",
"criteria",
"pick",
"out",
"the",
"keys",
"that",
"fulfill",
"them",
"from",
"a",
"given",
"set",
"of",
"keys",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwt.py#L33-L75 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwt.py | JWT.pack_init | def pack_init(self, recv, aud):
"""
Gather initial information for the payload.
:return: A dictionary with claims and values
"""
argv = {'iss': self.iss, 'iat': utc_time_sans_frac()}
if self.lifetime:
argv['exp'] = argv['iat'] + self.lifetime
_aud = ... | python | def pack_init(self, recv, aud):
"""
Gather initial information for the payload.
:return: A dictionary with claims and values
"""
argv = {'iss': self.iss, 'iat': utc_time_sans_frac()}
if self.lifetime:
argv['exp'] = argv['iat'] + self.lifetime
_aud = ... | [
"def",
"pack_init",
"(",
"self",
",",
"recv",
",",
"aud",
")",
":",
"argv",
"=",
"{",
"'iss'",
":",
"self",
".",
"iss",
",",
"'iat'",
":",
"utc_time_sans_frac",
"(",
")",
"}",
"if",
"self",
".",
"lifetime",
":",
"argv",
"[",
"'exp'",
"]",
"=",
"a... | Gather initial information for the payload.
:return: A dictionary with claims and values | [
"Gather",
"initial",
"information",
"for",
"the",
"payload",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwt.py#L155-L169 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwt.py | JWT.pack_key | def pack_key(self, owner_id='', kid=''):
"""
Find a key to be used for signing the Json Web Token
:param owner_id: Owner of the keys to chose from
:param kid: Key ID
:return: One key
"""
keys = pick_key(self.my_keys(owner_id, 'sig'), 'sig', alg=self.alg,
... | python | def pack_key(self, owner_id='', kid=''):
"""
Find a key to be used for signing the Json Web Token
:param owner_id: Owner of the keys to chose from
:param kid: Key ID
:return: One key
"""
keys = pick_key(self.my_keys(owner_id, 'sig'), 'sig', alg=self.alg,
... | [
"def",
"pack_key",
"(",
"self",
",",
"owner_id",
"=",
"''",
",",
"kid",
"=",
"''",
")",
":",
"keys",
"=",
"pick_key",
"(",
"self",
".",
"my_keys",
"(",
"owner_id",
",",
"'sig'",
")",
",",
"'sig'",
",",
"alg",
"=",
"self",
".",
"alg",
",",
"kid",
... | Find a key to be used for signing the Json Web Token
:param owner_id: Owner of the keys to chose from
:param kid: Key ID
:return: One key | [
"Find",
"a",
"key",
"to",
"be",
"used",
"for",
"signing",
"the",
"Json",
"Web",
"Token"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwt.py#L171-L185 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwt.py | JWT._verify | def _verify(self, rj, token):
"""
Verify a signed JSON Web Token
:param rj: A :py:class:`cryptojwt.jws.JWS` instance
:param token: The signed JSON Web Token
:return: A verified message
"""
keys = self.key_jar.get_jwt_verify_keys(rj.jwt)
return rj.verify_c... | python | def _verify(self, rj, token):
"""
Verify a signed JSON Web Token
:param rj: A :py:class:`cryptojwt.jws.JWS` instance
:param token: The signed JSON Web Token
:return: A verified message
"""
keys = self.key_jar.get_jwt_verify_keys(rj.jwt)
return rj.verify_c... | [
"def",
"_verify",
"(",
"self",
",",
"rj",
",",
"token",
")",
":",
"keys",
"=",
"self",
".",
"key_jar",
".",
"get_jwt_verify_keys",
"(",
"rj",
".",
"jwt",
")",
"return",
"rj",
".",
"verify_compact",
"(",
"token",
",",
"keys",
")"
] | Verify a signed JSON Web Token
:param rj: A :py:class:`cryptojwt.jws.JWS` instance
:param token: The signed JSON Web Token
:return: A verified message | [
"Verify",
"a",
"signed",
"JSON",
"Web",
"Token"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwt.py#L242-L251 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwt.py | JWT._decrypt | def _decrypt(self, rj, token):
"""
Decrypt an encrypted JsonWebToken
:param rj: :py:class:`cryptojwt.jwe.JWE` instance
:param token: The encrypted JsonWebToken
:return:
"""
if self.iss:
keys = self.key_jar.get_jwt_decrypt_keys(rj.jwt, aud=self.iss)
... | python | def _decrypt(self, rj, token):
"""
Decrypt an encrypted JsonWebToken
:param rj: :py:class:`cryptojwt.jwe.JWE` instance
:param token: The encrypted JsonWebToken
:return:
"""
if self.iss:
keys = self.key_jar.get_jwt_decrypt_keys(rj.jwt, aud=self.iss)
... | [
"def",
"_decrypt",
"(",
"self",
",",
"rj",
",",
"token",
")",
":",
"if",
"self",
".",
"iss",
":",
"keys",
"=",
"self",
".",
"key_jar",
".",
"get_jwt_decrypt_keys",
"(",
"rj",
".",
"jwt",
",",
"aud",
"=",
"self",
".",
"iss",
")",
"else",
":",
"key... | Decrypt an encrypted JsonWebToken
:param rj: :py:class:`cryptojwt.jwe.JWE` instance
:param token: The encrypted JsonWebToken
:return: | [
"Decrypt",
"an",
"encrypted",
"JsonWebToken"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwt.py#L253-L265 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwt.py | JWT.verify_profile | def verify_profile(msg_cls, info, **kwargs):
"""
If a message type is known for this JSON document. Verify that the
document complies with the message specifications.
:param msg_cls: The message class. A
:py:class:`oidcmsg.message.Message` instance
:param info: The i... | python | def verify_profile(msg_cls, info, **kwargs):
"""
If a message type is known for this JSON document. Verify that the
document complies with the message specifications.
:param msg_cls: The message class. A
:py:class:`oidcmsg.message.Message` instance
:param info: The i... | [
"def",
"verify_profile",
"(",
"msg_cls",
",",
"info",
",",
"*",
"*",
"kwargs",
")",
":",
"_msg",
"=",
"msg_cls",
"(",
"*",
"*",
"info",
")",
"if",
"not",
"_msg",
".",
"verify",
"(",
"*",
"*",
"kwargs",
")",
":",
"raise",
"VerificationError",
"(",
"... | If a message type is known for this JSON document. Verify that the
document complies with the message specifications.
:param msg_cls: The message class. A
:py:class:`oidcmsg.message.Message` instance
:param info: The information in the JSON document as a dictionary
:param kw... | [
"If",
"a",
"message",
"type",
"is",
"known",
"for",
"this",
"JSON",
"document",
".",
"Verify",
"that",
"the",
"document",
"complies",
"with",
"the",
"message",
"specifications",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwt.py#L268-L282 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwt.py | JWT.unpack | def unpack(self, token):
"""
Unpack a received signed or signed and encrypted Json Web Token
:param token: The Json Web Token
:return: If decryption and signature verification work the payload
will be returned as a Message instance if possible.
"""
if not tok... | python | def unpack(self, token):
"""
Unpack a received signed or signed and encrypted Json Web Token
:param token: The Json Web Token
:return: If decryption and signature verification work the payload
will be returned as a Message instance if possible.
"""
if not tok... | [
"def",
"unpack",
"(",
"self",
",",
"token",
")",
":",
"if",
"not",
"token",
":",
"raise",
"KeyError",
"_jwe_header",
"=",
"_jws_header",
"=",
"None",
"# Check if it's an encrypted JWT",
"darg",
"=",
"{",
"}",
"if",
"self",
".",
"allowed_enc_encs",
":",
"darg... | Unpack a received signed or signed and encrypted Json Web Token
:param token: The Json Web Token
:return: If decryption and signature verification work the payload
will be returned as a Message instance if possible. | [
"Unpack",
"a",
"received",
"signed",
"or",
"signed",
"and",
"encrypted",
"Json",
"Web",
"Token"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwt.py#L284-L367 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jws/jws.py | factory | def factory(token, alg=''):
"""
Instantiate an JWS instance if the token is a signed JWT.
:param token: The token that might be a signed JWT
:param alg: The expected signature algorithm
:return: A JWS instance if the token was a signed JWT, otherwise None
"""
_jw = JWS(alg=alg)
if _jw.... | python | def factory(token, alg=''):
"""
Instantiate an JWS instance if the token is a signed JWT.
:param token: The token that might be a signed JWT
:param alg: The expected signature algorithm
:return: A JWS instance if the token was a signed JWT, otherwise None
"""
_jw = JWS(alg=alg)
if _jw.... | [
"def",
"factory",
"(",
"token",
",",
"alg",
"=",
"''",
")",
":",
"_jw",
"=",
"JWS",
"(",
"alg",
"=",
"alg",
")",
"if",
"_jw",
".",
"is_jws",
"(",
"token",
")",
":",
"return",
"_jw",
"else",
":",
"return",
"None"
] | Instantiate an JWS instance if the token is a signed JWT.
:param token: The token that might be a signed JWT
:param alg: The expected signature algorithm
:return: A JWS instance if the token was a signed JWT, otherwise None | [
"Instantiate",
"an",
"JWS",
"instance",
"if",
"the",
"token",
"is",
"a",
"signed",
"JWT",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jws/jws.py#L434-L447 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jws/jws.py | JWS.sign_compact | def sign_compact(self, keys=None, protected=None, **kwargs):
"""
Produce a JWS using the JWS Compact Serialization
:param keys: A dictionary of keys
:param protected: The protected headers (a dictionary)
:param kwargs: claims you want to add to the standard headers
:retu... | python | def sign_compact(self, keys=None, protected=None, **kwargs):
"""
Produce a JWS using the JWS Compact Serialization
:param keys: A dictionary of keys
:param protected: The protected headers (a dictionary)
:param kwargs: claims you want to add to the standard headers
:retu... | [
"def",
"sign_compact",
"(",
"self",
",",
"keys",
"=",
"None",
",",
"protected",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"_headers",
"=",
"self",
".",
"_header",
"_headers",
".",
"update",
"(",
"kwargs",
")",
"key",
",",
"xargs",
",",
"_alg",
... | Produce a JWS using the JWS Compact Serialization
:param keys: A dictionary of keys
:param protected: The protected headers (a dictionary)
:param kwargs: claims you want to add to the standard headers
:return: A signed JSON Web Token | [
"Produce",
"a",
"JWS",
"using",
"the",
"JWS",
"Compact",
"Serialization"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jws/jws.py#L106-L143 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jws/jws.py | JWS.verify_compact | def verify_compact(self, jws=None, keys=None, allow_none=False,
sigalg=None):
"""
Verify a JWT signature
:param jws: A signed JSON Web Token
:param keys: A list of keys that can possibly be used to verify the
signature
:param allow_none: If sig... | python | def verify_compact(self, jws=None, keys=None, allow_none=False,
sigalg=None):
"""
Verify a JWT signature
:param jws: A signed JSON Web Token
:param keys: A list of keys that can possibly be used to verify the
signature
:param allow_none: If sig... | [
"def",
"verify_compact",
"(",
"self",
",",
"jws",
"=",
"None",
",",
"keys",
"=",
"None",
",",
"allow_none",
"=",
"False",
",",
"sigalg",
"=",
"None",
")",
":",
"return",
"self",
".",
"verify_compact_verbose",
"(",
"jws",
",",
"keys",
",",
"allow_none",
... | Verify a JWT signature
:param jws: A signed JSON Web Token
:param keys: A list of keys that can possibly be used to verify the
signature
:param allow_none: If signature algorithm 'none' is allowed
:param sigalg: Expected sigalg
:return: Dictionary with 2 keys 'msg' r... | [
"Verify",
"a",
"JWT",
"signature"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jws/jws.py#L145-L157 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jws/jws.py | JWS.verify_compact_verbose | def verify_compact_verbose(self, jws=None, keys=None, allow_none=False,
sigalg=None):
"""
Verify a JWT signature and return dict with validation results
:param jws: A signed JSON Web Token
:param keys: A list of keys that can possibly be used to verify the... | python | def verify_compact_verbose(self, jws=None, keys=None, allow_none=False,
sigalg=None):
"""
Verify a JWT signature and return dict with validation results
:param jws: A signed JSON Web Token
:param keys: A list of keys that can possibly be used to verify the... | [
"def",
"verify_compact_verbose",
"(",
"self",
",",
"jws",
"=",
"None",
",",
"keys",
"=",
"None",
",",
"allow_none",
"=",
"False",
",",
"sigalg",
"=",
"None",
")",
":",
"if",
"jws",
":",
"jwt",
"=",
"JWSig",
"(",
")",
".",
"unpack",
"(",
"jws",
")",... | Verify a JWT signature and return dict with validation results
:param jws: A signed JSON Web Token
:param keys: A list of keys that can possibly be used to verify the
signature
:param allow_none: If signature algorithm 'none' is allowed
:param sigalg: Expected sigalg
... | [
"Verify",
"a",
"JWT",
"signature",
"and",
"return",
"dict",
"with",
"validation",
"results"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jws/jws.py#L159-L250 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jws/jws.py | JWS.sign_json | def sign_json(self, keys=None, headers=None, flatten=False):
"""
Produce JWS using the JWS JSON Serialization
:param keys: list of keys to use for signing the JWS
:param headers: list of tuples (protected headers, unprotected
headers) for each signature
:return: A si... | python | def sign_json(self, keys=None, headers=None, flatten=False):
"""
Produce JWS using the JWS JSON Serialization
:param keys: list of keys to use for signing the JWS
:param headers: list of tuples (protected headers, unprotected
headers) for each signature
:return: A si... | [
"def",
"sign_json",
"(",
"self",
",",
"keys",
"=",
"None",
",",
"headers",
"=",
"None",
",",
"flatten",
"=",
"False",
")",
":",
"def",
"create_signature",
"(",
"protected",
",",
"unprotected",
")",
":",
"protected_headers",
"=",
"protected",
"or",
"{",
"... | Produce JWS using the JWS JSON Serialization
:param keys: list of keys to use for signing the JWS
:param headers: list of tuples (protected headers, unprotected
headers) for each signature
:return: A signed message using the JSON serialization format. | [
"Produce",
"JWS",
"using",
"the",
"JWS",
"JSON",
"Serialization"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jws/jws.py#L252-L293 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jws/jws.py | JWS._is_json_serialized_jws | def _is_json_serialized_jws(self, json_jws):
"""
Check if we've got a JSON serialized signed JWT.
:param json_jws: The message
:return: True/False
"""
json_ser_keys = {"payload", "signatures"}
flattened_json_ser_keys = {"payload", "signature"}
if not json... | python | def _is_json_serialized_jws(self, json_jws):
"""
Check if we've got a JSON serialized signed JWT.
:param json_jws: The message
:return: True/False
"""
json_ser_keys = {"payload", "signatures"}
flattened_json_ser_keys = {"payload", "signature"}
if not json... | [
"def",
"_is_json_serialized_jws",
"(",
"self",
",",
"json_jws",
")",
":",
"json_ser_keys",
"=",
"{",
"\"payload\"",
",",
"\"signatures\"",
"}",
"flattened_json_ser_keys",
"=",
"{",
"\"payload\"",
",",
"\"signature\"",
"}",
"if",
"not",
"json_ser_keys",
".",
"issub... | Check if we've got a JSON serialized signed JWT.
:param json_jws: The message
:return: True/False | [
"Check",
"if",
"we",
"ve",
"got",
"a",
"JSON",
"serialized",
"signed",
"JWT",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jws/jws.py#L360-L373 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jws/jws.py | JWS._is_compact_jws | def _is_compact_jws(self, jws):
"""
Check if we've got a compact signed JWT
:param jws: The message
:return: True/False
"""
try:
jwt = JWSig().unpack(jws)
except Exception as err:
logger.warning('Could not parse JWS: {}'.format(err))
... | python | def _is_compact_jws(self, jws):
"""
Check if we've got a compact signed JWT
:param jws: The message
:return: True/False
"""
try:
jwt = JWSig().unpack(jws)
except Exception as err:
logger.warning('Could not parse JWS: {}'.format(err))
... | [
"def",
"_is_compact_jws",
"(",
"self",
",",
"jws",
")",
":",
"try",
":",
"jwt",
"=",
"JWSig",
"(",
")",
".",
"unpack",
"(",
"jws",
")",
"except",
"Exception",
"as",
"err",
":",
"logger",
".",
"warning",
"(",
"'Could not parse JWS: {}'",
".",
"format",
... | Check if we've got a compact signed JWT
:param jws: The message
:return: True/False | [
"Check",
"if",
"we",
"ve",
"got",
"a",
"compact",
"signed",
"JWT"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jws/jws.py#L375-L399 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/hmac.py | SYMKey.appropriate_for | def appropriate_for(self, usage, alg='HS256'):
"""
Make sure there is a key instance present that can be used for
the specified usage.
"""
try:
_use = USE[usage]
except:
raise ValueError('Unknown key usage')
else:
if not self.us... | python | def appropriate_for(self, usage, alg='HS256'):
"""
Make sure there is a key instance present that can be used for
the specified usage.
"""
try:
_use = USE[usage]
except:
raise ValueError('Unknown key usage')
else:
if not self.us... | [
"def",
"appropriate_for",
"(",
"self",
",",
"usage",
",",
"alg",
"=",
"'HS256'",
")",
":",
"try",
":",
"_use",
"=",
"USE",
"[",
"usage",
"]",
"except",
":",
"raise",
"ValueError",
"(",
"'Unknown key usage'",
")",
"else",
":",
"if",
"not",
"self",
".",
... | Make sure there is a key instance present that can be used for
the specified usage. | [
"Make",
"sure",
"there",
"is",
"a",
"key",
"instance",
"present",
"that",
"can",
"be",
"used",
"for",
"the",
"specified",
"usage",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/hmac.py#L72-L88 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/hmac.py | SYMKey.encryption_key | def encryption_key(self, alg, **kwargs):
"""
Return an encryption key as per
http://openid.net/specs/openid-connect-core-1_0.html#Encryption
:param alg: encryption algorithm
:param kwargs:
:return: encryption key as byte string
"""
if not self.key:
... | python | def encryption_key(self, alg, **kwargs):
"""
Return an encryption key as per
http://openid.net/specs/openid-connect-core-1_0.html#Encryption
:param alg: encryption algorithm
:param kwargs:
:return: encryption key as byte string
"""
if not self.key:
... | [
"def",
"encryption_key",
"(",
"self",
",",
"alg",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"self",
".",
"key",
":",
"self",
".",
"deserialize",
"(",
")",
"try",
":",
"tsize",
"=",
"ALG2KEYLEN",
"[",
"alg",
"]",
"except",
"KeyError",
":",
"ra... | Return an encryption key as per
http://openid.net/specs/openid-connect-core-1_0.html#Encryption
:param alg: encryption algorithm
:param kwargs:
:return: encryption key as byte string | [
"Return",
"an",
"encryption",
"key",
"as",
"per",
"http",
":",
"//",
"openid",
".",
"net",
"/",
"specs",
"/",
"openid",
"-",
"connect",
"-",
"core",
"-",
"1_0",
".",
"html#Encryption"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/hmac.py#L90-L122 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jws/rsa.py | RSASigner.sign | def sign(self, msg, key):
"""
Create a signature over a message as defined in RFC7515 using an
RSA key
:param msg: the message.
:type msg: bytes
:returns: bytes, the signature of data.
:rtype: bytes
"""
if not isinstance(key, rsa.RSAPrivateKey):
... | python | def sign(self, msg, key):
"""
Create a signature over a message as defined in RFC7515 using an
RSA key
:param msg: the message.
:type msg: bytes
:returns: bytes, the signature of data.
:rtype: bytes
"""
if not isinstance(key, rsa.RSAPrivateKey):
... | [
"def",
"sign",
"(",
"self",
",",
"msg",
",",
"key",
")",
":",
"if",
"not",
"isinstance",
"(",
"key",
",",
"rsa",
".",
"RSAPrivateKey",
")",
":",
"raise",
"TypeError",
"(",
"\"The key must be an instance of rsa.RSAPrivateKey\"",
")",
"sig",
"=",
"key",
".",
... | Create a signature over a message as defined in RFC7515 using an
RSA key
:param msg: the message.
:type msg: bytes
:returns: bytes, the signature of data.
:rtype: bytes | [
"Create",
"a",
"signature",
"over",
"a",
"message",
"as",
"defined",
"in",
"RFC7515",
"using",
"an",
"RSA",
"key"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jws/rsa.py#L14-L29 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jws/rsa.py | RSASigner.verify | def verify(self, msg, signature, key):
"""
Verifies whether signature is a valid signature for message
:param msg: the message
:type msg: bytes
:param signature: The signature to be verified
:type signature: bytes
:param key: The key
:return: True is the ... | python | def verify(self, msg, signature, key):
"""
Verifies whether signature is a valid signature for message
:param msg: the message
:type msg: bytes
:param signature: The signature to be verified
:type signature: bytes
:param key: The key
:return: True is the ... | [
"def",
"verify",
"(",
"self",
",",
"msg",
",",
"signature",
",",
"key",
")",
":",
"if",
"not",
"isinstance",
"(",
"key",
",",
"rsa",
".",
"RSAPublicKey",
")",
":",
"raise",
"TypeError",
"(",
"\"The public key must be an instance of RSAPublicKey\"",
")",
"try",... | Verifies whether signature is a valid signature for message
:param msg: the message
:type msg: bytes
:param signature: The signature to be verified
:type signature: bytes
:param key: The key
:return: True is the signature is valid otherwise False | [
"Verifies",
"whether",
"signature",
"is",
"a",
"valid",
"signature",
"for",
"message"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jws/rsa.py#L31-L53 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/asym.py | AsymmetricKey.appropriate_for | def appropriate_for(self, usage, **kwargs):
"""
Make sure there is a key instance present that can be used for
the specified usage.
:param usage: Usage specification, one of [sign, verify, decrypt,
encrypt]
:param kwargs: Extra keyword arguments
:return: Suit... | python | def appropriate_for(self, usage, **kwargs):
"""
Make sure there is a key instance present that can be used for
the specified usage.
:param usage: Usage specification, one of [sign, verify, decrypt,
encrypt]
:param kwargs: Extra keyword arguments
:return: Suit... | [
"def",
"appropriate_for",
"(",
"self",
",",
"usage",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"_use",
"=",
"USE",
"[",
"usage",
"]",
"except",
"KeyError",
":",
"raise",
"ValueError",
"(",
"'Unknown key usage'",
")",
"else",
":",
"if",
"usage",
"i... | Make sure there is a key instance present that can be used for
the specified usage.
:param usage: Usage specification, one of [sign, verify, decrypt,
encrypt]
:param kwargs: Extra keyword arguments
:return: Suitable key or None | [
"Make",
"sure",
"there",
"is",
"a",
"key",
"instance",
"present",
"that",
"can",
"be",
"used",
"for",
"the",
"specified",
"usage",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/asym.py#L16-L40 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/rsa.py | generate_and_store_rsa_key | def generate_and_store_rsa_key(key_size=2048, filename='rsa.key',
passphrase=''):
"""
Generate a private RSA key and store a PEM representation of it in a
file.
:param key_size: The size of the key, default 2048 bytes.
:param filename: The name of the file to which th... | python | def generate_and_store_rsa_key(key_size=2048, filename='rsa.key',
passphrase=''):
"""
Generate a private RSA key and store a PEM representation of it in a
file.
:param key_size: The size of the key, default 2048 bytes.
:param filename: The name of the file to which th... | [
"def",
"generate_and_store_rsa_key",
"(",
"key_size",
"=",
"2048",
",",
"filename",
"=",
"'rsa.key'",
",",
"passphrase",
"=",
"''",
")",
":",
"private_key",
"=",
"rsa",
".",
"generate_private_key",
"(",
"public_exponent",
"=",
"65537",
",",
"key_size",
"=",
"k... | Generate a private RSA key and store a PEM representation of it in a
file.
:param key_size: The size of the key, default 2048 bytes.
:param filename: The name of the file to which the key should be written
:param passphrase: If the PEM representation should be protected with a
pass phrase.
... | [
"Generate",
"a",
"private",
"RSA",
"key",
"and",
"store",
"a",
"PEM",
"representation",
"of",
"it",
"in",
"a",
"file",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/rsa.py#L29-L60 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/rsa.py | import_public_rsa_key_from_file | def import_public_rsa_key_from_file(filename):
"""
Read a public RSA key from a PEM file.
:param filename: The name of the file
:param passphrase: A pass phrase to use to unpack the PEM file.
:return: A
cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey instance
"""
with ope... | python | def import_public_rsa_key_from_file(filename):
"""
Read a public RSA key from a PEM file.
:param filename: The name of the file
:param passphrase: A pass phrase to use to unpack the PEM file.
:return: A
cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey instance
"""
with ope... | [
"def",
"import_public_rsa_key_from_file",
"(",
"filename",
")",
":",
"with",
"open",
"(",
"filename",
",",
"\"rb\"",
")",
"as",
"key_file",
":",
"public_key",
"=",
"serialization",
".",
"load_pem_public_key",
"(",
"key_file",
".",
"read",
"(",
")",
",",
"backe... | Read a public RSA key from a PEM file.
:param filename: The name of the file
:param passphrase: A pass phrase to use to unpack the PEM file.
:return: A
cryptography.hazmat.primitives.asymmetric.rsa.RSAPublicKey instance | [
"Read",
"a",
"public",
"RSA",
"key",
"from",
"a",
"PEM",
"file",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/rsa.py#L80-L93 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/rsa.py | import_rsa_key | def import_rsa_key(pem_data):
"""
Extract an RSA key from a PEM-encoded X.509 certificate
:param pem_data: RSA key encoded in standard form
:return: rsa.RSAPublicKey instance
"""
if not pem_data.startswith(PREFIX):
pem_data = bytes('{}\n{}\n{}'.format(PREFIX, pem_data, POSTFIX),
... | python | def import_rsa_key(pem_data):
"""
Extract an RSA key from a PEM-encoded X.509 certificate
:param pem_data: RSA key encoded in standard form
:return: rsa.RSAPublicKey instance
"""
if not pem_data.startswith(PREFIX):
pem_data = bytes('{}\n{}\n{}'.format(PREFIX, pem_data, POSTFIX),
... | [
"def",
"import_rsa_key",
"(",
"pem_data",
")",
":",
"if",
"not",
"pem_data",
".",
"startswith",
"(",
"PREFIX",
")",
":",
"pem_data",
"=",
"bytes",
"(",
"'{}\\n{}\\n{}'",
".",
"format",
"(",
"PREFIX",
",",
"pem_data",
",",
"POSTFIX",
")",
",",
"'utf-8'",
... | Extract an RSA key from a PEM-encoded X.509 certificate
:param pem_data: RSA key encoded in standard form
:return: rsa.RSAPublicKey instance | [
"Extract",
"an",
"RSA",
"key",
"from",
"a",
"PEM",
"-",
"encoded",
"X",
".",
"509",
"certificate"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/rsa.py#L96-L109 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/rsa.py | rsa_eq | def rsa_eq(key1, key2):
"""
Only works for RSAPublic Keys
:param key1:
:param key2:
:return:
"""
pn1 = key1.public_numbers()
pn2 = key2.public_numbers()
# Check if two RSA keys are in fact the same
if pn1 == pn2:
return True
else:
return False | python | def rsa_eq(key1, key2):
"""
Only works for RSAPublic Keys
:param key1:
:param key2:
:return:
"""
pn1 = key1.public_numbers()
pn2 = key2.public_numbers()
# Check if two RSA keys are in fact the same
if pn1 == pn2:
return True
else:
return False | [
"def",
"rsa_eq",
"(",
"key1",
",",
"key2",
")",
":",
"pn1",
"=",
"key1",
".",
"public_numbers",
"(",
")",
"pn2",
"=",
"key2",
".",
"public_numbers",
"(",
")",
"# Check if two RSA keys are in fact the same",
"if",
"pn1",
"==",
"pn2",
":",
"return",
"True",
... | Only works for RSAPublic Keys
:param key1:
:param key2:
:return: | [
"Only",
"works",
"for",
"RSAPublic",
"Keys"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/rsa.py#L117-L131 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/rsa.py | x509_rsa_load | def x509_rsa_load(txt):
""" So I get the same output format as loads produces
:param txt:
:return:
"""
pub_key = import_rsa_key(txt)
if isinstance(pub_key, rsa.RSAPublicKey):
return [("rsa", pub_key)] | python | def x509_rsa_load(txt):
""" So I get the same output format as loads produces
:param txt:
:return:
"""
pub_key = import_rsa_key(txt)
if isinstance(pub_key, rsa.RSAPublicKey):
return [("rsa", pub_key)] | [
"def",
"x509_rsa_load",
"(",
"txt",
")",
":",
"pub_key",
"=",
"import_rsa_key",
"(",
"txt",
")",
"if",
"isinstance",
"(",
"pub_key",
",",
"rsa",
".",
"RSAPublicKey",
")",
":",
"return",
"[",
"(",
"\"rsa\"",
",",
"pub_key",
")",
"]"
] | So I get the same output format as loads produces
:param txt:
:return: | [
"So",
"I",
"get",
"the",
"same",
"output",
"format",
"as",
"loads",
"produces",
":",
"param",
"txt",
":",
":",
"return",
":"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/rsa.py#L134-L141 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/rsa.py | der_cert | def der_cert(der_data):
"""
Load a DER encoded certificate
:param der_data: DER-encoded certificate
:return: A cryptography.x509.certificate instance
"""
if isinstance(der_data, str):
der_data = bytes(der_data, 'utf-8')
return x509.load_der_x509_certificate(der_data, default_backend... | python | def der_cert(der_data):
"""
Load a DER encoded certificate
:param der_data: DER-encoded certificate
:return: A cryptography.x509.certificate instance
"""
if isinstance(der_data, str):
der_data = bytes(der_data, 'utf-8')
return x509.load_der_x509_certificate(der_data, default_backend... | [
"def",
"der_cert",
"(",
"der_data",
")",
":",
"if",
"isinstance",
"(",
"der_data",
",",
"str",
")",
":",
"der_data",
"=",
"bytes",
"(",
"der_data",
",",
"'utf-8'",
")",
"return",
"x509",
".",
"load_der_x509_certificate",
"(",
"der_data",
",",
"default_backen... | Load a DER encoded certificate
:param der_data: DER-encoded certificate
:return: A cryptography.x509.certificate instance | [
"Load",
"a",
"DER",
"encoded",
"certificate"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/rsa.py#L189-L198 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/rsa.py | load_x509_cert | def load_x509_cert(url, httpc, spec2key, **get_args):
"""
Get and transform a X509 cert into a key.
:param url: Where the X509 cert can be found
:param httpc: HTTP client to use for fetching
:param spec2key: A dictionary over keys already seen
:param get_args: Extra key word arguments to the HT... | python | def load_x509_cert(url, httpc, spec2key, **get_args):
"""
Get and transform a X509 cert into a key.
:param url: Where the X509 cert can be found
:param httpc: HTTP client to use for fetching
:param spec2key: A dictionary over keys already seen
:param get_args: Extra key word arguments to the HT... | [
"def",
"load_x509_cert",
"(",
"url",
",",
"httpc",
",",
"spec2key",
",",
"*",
"*",
"get_args",
")",
":",
"try",
":",
"r",
"=",
"httpc",
"(",
"'GET'",
",",
"url",
",",
"allow_redirects",
"=",
"True",
",",
"*",
"*",
"get_args",
")",
"if",
"r",
".",
... | Get and transform a X509 cert into a key.
:param url: Where the X509 cert can be found
:param httpc: HTTP client to use for fetching
:param spec2key: A dictionary over keys already seen
:param get_args: Extra key word arguments to the HTTP GET request
:return: List of 2-tuples (keytype, key) | [
"Get",
"and",
"transform",
"a",
"X509",
"cert",
"into",
"a",
"key",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/rsa.py#L201-L226 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/rsa.py | cmp_public_numbers | def cmp_public_numbers(pn1, pn2):
"""
Compare 2 sets of public numbers. These is a way to compare
2 public RSA keys. If the sets are the same then the keys are the same.
:param pn1: The set of values belonging to the 1st key
:param pn2: The set of values belonging to the 2nd key
:return: True i... | python | def cmp_public_numbers(pn1, pn2):
"""
Compare 2 sets of public numbers. These is a way to compare
2 public RSA keys. If the sets are the same then the keys are the same.
:param pn1: The set of values belonging to the 1st key
:param pn2: The set of values belonging to the 2nd key
:return: True i... | [
"def",
"cmp_public_numbers",
"(",
"pn1",
",",
"pn2",
")",
":",
"if",
"pn1",
".",
"n",
"==",
"pn2",
".",
"n",
":",
"if",
"pn1",
".",
"e",
"==",
"pn2",
".",
"e",
":",
"return",
"True",
"return",
"False"
] | Compare 2 sets of public numbers. These is a way to compare
2 public RSA keys. If the sets are the same then the keys are the same.
:param pn1: The set of values belonging to the 1st key
:param pn2: The set of values belonging to the 2nd key
:return: True is the sets are the same otherwise False. | [
"Compare",
"2",
"sets",
"of",
"public",
"numbers",
".",
"These",
"is",
"a",
"way",
"to",
"compare",
"2",
"public",
"RSA",
"keys",
".",
"If",
"the",
"sets",
"are",
"the",
"same",
"then",
"the",
"keys",
"are",
"the",
"same",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/rsa.py#L229-L241 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/rsa.py | cmp_private_numbers | def cmp_private_numbers(pn1, pn2):
"""
Compare 2 sets of private numbers. This is for comparing 2
private RSA keys.
:param pn1: The set of values belonging to the 1st key
:param pn2: The set of values belonging to the 2nd key
:return: True is the sets are the same otherwise False.
"""
i... | python | def cmp_private_numbers(pn1, pn2):
"""
Compare 2 sets of private numbers. This is for comparing 2
private RSA keys.
:param pn1: The set of values belonging to the 1st key
:param pn2: The set of values belonging to the 2nd key
:return: True is the sets are the same otherwise False.
"""
i... | [
"def",
"cmp_private_numbers",
"(",
"pn1",
",",
"pn2",
")",
":",
"if",
"not",
"cmp_public_numbers",
"(",
"pn1",
".",
"public_numbers",
",",
"pn2",
".",
"public_numbers",
")",
":",
"return",
"False",
"for",
"param",
"in",
"[",
"'d'",
",",
"'p'",
",",
"'q'"... | Compare 2 sets of private numbers. This is for comparing 2
private RSA keys.
:param pn1: The set of values belonging to the 1st key
:param pn2: The set of values belonging to the 2nd key
:return: True is the sets are the same otherwise False. | [
"Compare",
"2",
"sets",
"of",
"private",
"numbers",
".",
"This",
"is",
"for",
"comparing",
"2",
"private",
"RSA",
"keys",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/rsa.py#L244-L259 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/rsa.py | x5t_calculation | def x5t_calculation(cert):
"""
base64url-encoded SHA-1 thumbprint (a.k.a. digest) of the DER
encoding of an X.509 certificate.
:param cert: DER encoded X.509 certificate
:return: x5t value
"""
if isinstance(cert, str):
der_cert = base64.b64decode(cert.encode('ascii'))
else:
... | python | def x5t_calculation(cert):
"""
base64url-encoded SHA-1 thumbprint (a.k.a. digest) of the DER
encoding of an X.509 certificate.
:param cert: DER encoded X.509 certificate
:return: x5t value
"""
if isinstance(cert, str):
der_cert = base64.b64decode(cert.encode('ascii'))
else:
... | [
"def",
"x5t_calculation",
"(",
"cert",
")",
":",
"if",
"isinstance",
"(",
"cert",
",",
"str",
")",
":",
"der_cert",
"=",
"base64",
".",
"b64decode",
"(",
"cert",
".",
"encode",
"(",
"'ascii'",
")",
")",
"else",
":",
"der_cert",
"=",
"base64",
".",
"b... | base64url-encoded SHA-1 thumbprint (a.k.a. digest) of the DER
encoding of an X.509 certificate.
:param cert: DER encoded X.509 certificate
:return: x5t value | [
"base64url",
"-",
"encoded",
"SHA",
"-",
"1",
"thumbprint",
"(",
"a",
".",
"k",
".",
"a",
".",
"digest",
")",
"of",
"the",
"DER",
"encoding",
"of",
"an",
"X",
".",
"509",
"certificate",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/rsa.py#L262-L275 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/rsa.py | new_rsa_key | def new_rsa_key(key_size=2048, kid='', use='', public_exponent=65537):
"""
Creates a new RSA key pair and wraps it in a
:py:class:`cryptojwt.jwk.rsa.RSAKey` instance
:param key_size: The size of the key
:param kid: The key ID
:param use: What the is supposed to be used for. 2 choices 'sig'/'enc... | python | def new_rsa_key(key_size=2048, kid='', use='', public_exponent=65537):
"""
Creates a new RSA key pair and wraps it in a
:py:class:`cryptojwt.jwk.rsa.RSAKey` instance
:param key_size: The size of the key
:param kid: The key ID
:param use: What the is supposed to be used for. 2 choices 'sig'/'enc... | [
"def",
"new_rsa_key",
"(",
"key_size",
"=",
"2048",
",",
"kid",
"=",
"''",
",",
"use",
"=",
"''",
",",
"public_exponent",
"=",
"65537",
")",
":",
"_key",
"=",
"rsa",
".",
"generate_private_key",
"(",
"public_exponent",
"=",
"public_exponent",
",",
"key_siz... | Creates a new RSA key pair and wraps it in a
:py:class:`cryptojwt.jwk.rsa.RSAKey` instance
:param key_size: The size of the key
:param kid: The key ID
:param use: What the is supposed to be used for. 2 choices 'sig'/'enc'
:param public_exponent: The value of the public exponent.
:return: A :py:... | [
"Creates",
"a",
"new",
"RSA",
"key",
"pair",
"and",
"wraps",
"it",
"in",
"a",
":",
"py",
":",
"class",
":",
"cryptojwt",
".",
"jwk",
".",
"rsa",
".",
"RSAKey",
"instance"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/rsa.py#L503-L523 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/rsa.py | RSAKey.deserialize | def deserialize(self):
"""
Based on a text based representation of an RSA key this method
instantiates a
cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey or
RSAPublicKey instance
"""
# first look for the public parts of a RSA key
if self.n and... | python | def deserialize(self):
"""
Based on a text based representation of an RSA key this method
instantiates a
cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey or
RSAPublicKey instance
"""
# first look for the public parts of a RSA key
if self.n and... | [
"def",
"deserialize",
"(",
"self",
")",
":",
"# first look for the public parts of a RSA key",
"if",
"self",
".",
"n",
"and",
"self",
".",
"e",
":",
"try",
":",
"numbers",
"=",
"{",
"}",
"# loop over all the parameters that define a RSA key",
"for",
"param",
"in",
... | Based on a text based representation of an RSA key this method
instantiates a
cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey or
RSAPublicKey instance | [
"Based",
"on",
"a",
"text",
"based",
"representation",
"of",
"an",
"RSA",
"key",
"this",
"method",
"instantiates",
"a",
"cryptography",
".",
"hazmat",
".",
"primitives",
".",
"asymmetric",
".",
"rsa",
".",
"RSAPrivateKey",
"or",
"RSAPublicKey",
"instance"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/rsa.py#L340-L400 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/rsa.py | RSAKey.serialize | def serialize(self, private=False):
"""
Given a cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey or
RSAPublicKey instance construct the JWK representation.
:param private: Should I do the private part or not
:return: A JWK as a dictionary
"""
if not se... | python | def serialize(self, private=False):
"""
Given a cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey or
RSAPublicKey instance construct the JWK representation.
:param private: Should I do the private part or not
:return: A JWK as a dictionary
"""
if not se... | [
"def",
"serialize",
"(",
"self",
",",
"private",
"=",
"False",
")",
":",
"if",
"not",
"self",
".",
"priv_key",
"and",
"not",
"self",
".",
"pub_key",
":",
"raise",
"SerializationNotPossible",
"(",
")",
"res",
"=",
"self",
".",
"common",
"(",
")",
"publi... | Given a cryptography.hazmat.primitives.asymmetric.rsa.RSAPrivateKey or
RSAPublicKey instance construct the JWK representation.
:param private: Should I do the private part or not
:return: A JWK as a dictionary | [
"Given",
"a",
"cryptography",
".",
"hazmat",
".",
"primitives",
".",
"asymmetric",
".",
"rsa",
".",
"RSAPrivateKey",
"or",
"RSAPublicKey",
"instance",
"construct",
"the",
"JWK",
"representation",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/rsa.py#L402-L432 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jwk/rsa.py | RSAKey.load_key | def load_key(self, key):
"""
Load a RSA key. Try to serialize the key before binding it to this
instance.
:param key: An RSA key instance
"""
self._serialize(key)
if isinstance(key, rsa.RSAPrivateKey):
self.priv_key = key
self.pub_key = k... | python | def load_key(self, key):
"""
Load a RSA key. Try to serialize the key before binding it to this
instance.
:param key: An RSA key instance
"""
self._serialize(key)
if isinstance(key, rsa.RSAPrivateKey):
self.priv_key = key
self.pub_key = k... | [
"def",
"load_key",
"(",
"self",
",",
"key",
")",
":",
"self",
".",
"_serialize",
"(",
"key",
")",
"if",
"isinstance",
"(",
"key",
",",
"rsa",
".",
"RSAPrivateKey",
")",
":",
"self",
".",
"priv_key",
"=",
"key",
"self",
".",
"pub_key",
"=",
"key",
"... | Load a RSA key. Try to serialize the key before binding it to this
instance.
:param key: An RSA key instance | [
"Load",
"a",
"RSA",
"key",
".",
"Try",
"to",
"serialize",
"the",
"key",
"before",
"binding",
"it",
"to",
"this",
"instance",
"."
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jwk/rsa.py#L449-L464 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jws/dsa.py | ECDSASigner.sign | def sign(self, msg, key):
"""
Create a signature over a message as defined in RFC7515 using an
Elliptic curve key
:param msg: The message
:param key: An ec.EllipticCurvePrivateKey instance
:return:
"""
if not isinstance(key, ec.EllipticCurvePrivateKey):
... | python | def sign(self, msg, key):
"""
Create a signature over a message as defined in RFC7515 using an
Elliptic curve key
:param msg: The message
:param key: An ec.EllipticCurvePrivateKey instance
:return:
"""
if not isinstance(key, ec.EllipticCurvePrivateKey):
... | [
"def",
"sign",
"(",
"self",
",",
"msg",
",",
"key",
")",
":",
"if",
"not",
"isinstance",
"(",
"key",
",",
"ec",
".",
"EllipticCurvePrivateKey",
")",
":",
"raise",
"TypeError",
"(",
"\"The private key must be an instance of \"",
"\"ec.EllipticCurvePrivateKey\"",
")... | Create a signature over a message as defined in RFC7515 using an
Elliptic curve key
:param msg: The message
:param key: An ec.EllipticCurvePrivateKey instance
:return: | [
"Create",
"a",
"signature",
"over",
"a",
"message",
"as",
"defined",
"in",
"RFC7515",
"using",
"an",
"Elliptic",
"curve",
"key"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jws/dsa.py#L31-L53 |
openid/JWTConnect-Python-CryptoJWT | src/cryptojwt/jws/dsa.py | ECDSASigner.verify | def verify(self, msg, sig, key):
"""
Verify a message signature
:param msg: The message
:param sig: A signature
:param key: A ec.EllipticCurvePublicKey to use for the verification.
:raises: BadSignature if the signature can't be verified.
:return: True
""... | python | def verify(self, msg, sig, key):
"""
Verify a message signature
:param msg: The message
:param sig: A signature
:param key: A ec.EllipticCurvePublicKey to use for the verification.
:raises: BadSignature if the signature can't be verified.
:return: True
""... | [
"def",
"verify",
"(",
"self",
",",
"msg",
",",
"sig",
",",
"key",
")",
":",
"if",
"not",
"isinstance",
"(",
"key",
",",
"ec",
".",
"EllipticCurvePublicKey",
")",
":",
"raise",
"TypeError",
"(",
"\"The public key must be an instance of \"",
"\"ec.EllipticCurvePub... | Verify a message signature
:param msg: The message
:param sig: A signature
:param key: A ec.EllipticCurvePublicKey to use for the verification.
:raises: BadSignature if the signature can't be verified.
:return: True | [
"Verify",
"a",
"message",
"signature"
] | train | https://github.com/openid/JWTConnect-Python-CryptoJWT/blob/8863cfbfe77ca885084870b234a66b55bd52930c/src/cryptojwt/jws/dsa.py#L55-L85 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.