repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/caches/__init__.py | _encrypted_data_keys_hash | def _encrypted_data_keys_hash(hasher, encrypted_data_keys):
"""Generates the expected hash for the provided encrypted data keys.
:param hasher: Existing hasher to use
:type hasher: cryptography.hazmat.primitives.hashes.Hash
:param iterable encrypted_data_keys: Encrypted data keys to hash
:returns: ... | python | def _encrypted_data_keys_hash(hasher, encrypted_data_keys):
"""Generates the expected hash for the provided encrypted data keys.
:param hasher: Existing hasher to use
:type hasher: cryptography.hazmat.primitives.hashes.Hash
:param iterable encrypted_data_keys: Encrypted data keys to hash
:returns: ... | [
"def",
"_encrypted_data_keys_hash",
"(",
"hasher",
",",
"encrypted_data_keys",
")",
":",
"hashed_keys",
"=",
"[",
"]",
"for",
"edk",
"in",
"encrypted_data_keys",
":",
"serialized_edk",
"=",
"serialize_encrypted_data_key",
"(",
"edk",
")",
"_hasher",
"=",
"hasher",
... | Generates the expected hash for the provided encrypted data keys.
:param hasher: Existing hasher to use
:type hasher: cryptography.hazmat.primitives.hashes.Hash
:param iterable encrypted_data_keys: Encrypted data keys to hash
:returns: Concatenated, sorted, list of all hashes
:rtype: bytes | [
"Generates",
"the",
"expected",
"hash",
"for",
"the",
"provided",
"encrypted",
"data",
"keys",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/caches/__init__.py#L89-L104 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/caches/__init__.py | build_decryption_materials_cache_key | def build_decryption_materials_cache_key(partition, request):
"""Generates a cache key for a decrypt request.
:param bytes partition: Partition name for which to generate key
:param request: Request for which to generate key
:type request: aws_encryption_sdk.materials_managers.DecryptionMaterialsReques... | python | def build_decryption_materials_cache_key(partition, request):
"""Generates a cache key for a decrypt request.
:param bytes partition: Partition name for which to generate key
:param request: Request for which to generate key
:type request: aws_encryption_sdk.materials_managers.DecryptionMaterialsReques... | [
"def",
"build_decryption_materials_cache_key",
"(",
"partition",
",",
"request",
")",
":",
"hasher",
"=",
"_new_cache_key_hasher",
"(",
")",
"_partition_hash",
"=",
"_partition_name_hash",
"(",
"hasher",
"=",
"hasher",
".",
"copy",
"(",
")",
",",
"partition_name",
... | Generates a cache key for a decrypt request.
:param bytes partition: Partition name for which to generate key
:param request: Request for which to generate key
:type request: aws_encryption_sdk.materials_managers.DecryptionMaterialsRequest
:returns: cache key
:rtype: bytes | [
"Generates",
"a",
"cache",
"key",
"for",
"a",
"decrypt",
"request",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/caches/__init__.py#L111-L131 | train |
aws/aws-encryption-sdk-python | examples/src/basic_file_encryption_with_raw_key_provider.py | cycle_file | def cycle_file(source_plaintext_filename):
"""Encrypts and then decrypts a file under a custom static master key provider.
:param str source_plaintext_filename: Filename of file to encrypt
"""
# Create a static random master key provider
key_id = os.urandom(8)
master_key_provider = StaticRandom... | python | def cycle_file(source_plaintext_filename):
"""Encrypts and then decrypts a file under a custom static master key provider.
:param str source_plaintext_filename: Filename of file to encrypt
"""
# Create a static random master key provider
key_id = os.urandom(8)
master_key_provider = StaticRandom... | [
"def",
"cycle_file",
"(",
"source_plaintext_filename",
")",
":",
"# Create a static random master key provider",
"key_id",
"=",
"os",
".",
"urandom",
"(",
"8",
")",
"master_key_provider",
"=",
"StaticRandomMasterKeyProvider",
"(",
")",
"master_key_provider",
".",
"add_mas... | Encrypts and then decrypts a file under a custom static master key provider.
:param str source_plaintext_filename: Filename of file to encrypt | [
"Encrypts",
"and",
"then",
"decrypts",
"a",
"file",
"under",
"a",
"custom",
"static",
"master",
"key",
"provider",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/examples/src/basic_file_encryption_with_raw_key_provider.py#L51-L88 | train |
aws/aws-encryption-sdk-python | examples/src/basic_file_encryption_with_raw_key_provider.py | StaticRandomMasterKeyProvider._get_raw_key | def _get_raw_key(self, key_id):
"""Returns a static, randomly-generated symmetric key for the specified key ID.
:param str key_id: Key ID
:returns: Wrapping key that contains the specified static key
:rtype: :class:`aws_encryption_sdk.internal.crypto.WrappingKey`
"""
try... | python | def _get_raw_key(self, key_id):
"""Returns a static, randomly-generated symmetric key for the specified key ID.
:param str key_id: Key ID
:returns: Wrapping key that contains the specified static key
:rtype: :class:`aws_encryption_sdk.internal.crypto.WrappingKey`
"""
try... | [
"def",
"_get_raw_key",
"(",
"self",
",",
"key_id",
")",
":",
"try",
":",
"static_key",
"=",
"self",
".",
"_static_keys",
"[",
"key_id",
"]",
"except",
"KeyError",
":",
"static_key",
"=",
"os",
".",
"urandom",
"(",
"32",
")",
"self",
".",
"_static_keys",
... | Returns a static, randomly-generated symmetric key for the specified key ID.
:param str key_id: Key ID
:returns: Wrapping key that contains the specified static key
:rtype: :class:`aws_encryption_sdk.internal.crypto.WrappingKey` | [
"Returns",
"a",
"static",
"randomly",
"-",
"generated",
"symmetric",
"key",
"for",
"the",
"specified",
"key",
"ID",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/examples/src/basic_file_encryption_with_raw_key_provider.py#L32-L48 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/streaming_client.py | _EncryptionStream.stream_length | def stream_length(self):
"""Returns the length of the source stream, determining it if not already known."""
if self._stream_length is None:
try:
current_position = self.source_stream.tell()
self.source_stream.seek(0, 2)
self._stream_length = s... | python | def stream_length(self):
"""Returns the length of the source stream, determining it if not already known."""
if self._stream_length is None:
try:
current_position = self.source_stream.tell()
self.source_stream.seek(0, 2)
self._stream_length = s... | [
"def",
"stream_length",
"(",
"self",
")",
":",
"if",
"self",
".",
"_stream_length",
"is",
"None",
":",
"try",
":",
"current_position",
"=",
"self",
".",
"source_stream",
".",
"tell",
"(",
")",
"self",
".",
"source_stream",
".",
"seek",
"(",
"0",
",",
"... | Returns the length of the source stream, determining it if not already known. | [
"Returns",
"the",
"length",
"of",
"the",
"source",
"stream",
"determining",
"it",
"if",
"not",
"already",
"known",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/streaming_client.py#L173-L184 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/streaming_client.py | _EncryptionStream.read | def read(self, b=-1):
"""Returns either the requested number of bytes or the entire stream.
:param int b: Number of bytes to read
:returns: Processed (encrypted or decrypted) bytes from source stream
:rtype: bytes
"""
# Any negative value for b is interpreted as a full r... | python | def read(self, b=-1):
"""Returns either the requested number of bytes or the entire stream.
:param int b: Number of bytes to read
:returns: Processed (encrypted or decrypted) bytes from source stream
:rtype: bytes
"""
# Any negative value for b is interpreted as a full r... | [
"def",
"read",
"(",
"self",
",",
"b",
"=",
"-",
"1",
")",
":",
"# Any negative value for b is interpreted as a full read",
"# None is also accepted for legacy compatibility",
"if",
"b",
"is",
"None",
"or",
"b",
"<",
"0",
":",
"b",
"=",
"-",
"1",
"_LOGGER",
".",
... | Returns either the requested number of bytes or the entire stream.
:param int b: Number of bytes to read
:returns: Processed (encrypted or decrypted) bytes from source stream
:rtype: bytes | [
"Returns",
"either",
"the",
"requested",
"number",
"of",
"bytes",
"or",
"the",
"entire",
"stream",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/streaming_client.py#L220-L254 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/streaming_client.py | _EncryptionStream.readline | def readline(self):
"""Read a chunk of the output"""
_LOGGER.info("reading line")
line = self.read(self.line_length)
if len(line) < self.line_length:
_LOGGER.info("all lines read")
return line | python | def readline(self):
"""Read a chunk of the output"""
_LOGGER.info("reading line")
line = self.read(self.line_length)
if len(line) < self.line_length:
_LOGGER.info("all lines read")
return line | [
"def",
"readline",
"(",
"self",
")",
":",
"_LOGGER",
".",
"info",
"(",
"\"reading line\"",
")",
"line",
"=",
"self",
".",
"read",
"(",
"self",
".",
"line_length",
")",
"if",
"len",
"(",
"line",
")",
"<",
"self",
".",
"line_length",
":",
"_LOGGER",
".... | Read a chunk of the output | [
"Read",
"a",
"chunk",
"of",
"the",
"output"
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/streaming_client.py#L276-L282 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/streaming_client.py | _EncryptionStream.next | def next(self):
"""Provides hook for Python2 iterator functionality."""
_LOGGER.debug("reading next")
if self.closed:
_LOGGER.debug("stream is closed")
raise StopIteration()
line = self.readline()
if not line:
_LOGGER.debug("nothing more to re... | python | def next(self):
"""Provides hook for Python2 iterator functionality."""
_LOGGER.debug("reading next")
if self.closed:
_LOGGER.debug("stream is closed")
raise StopIteration()
line = self.readline()
if not line:
_LOGGER.debug("nothing more to re... | [
"def",
"next",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"reading next\"",
")",
"if",
"self",
".",
"closed",
":",
"_LOGGER",
".",
"debug",
"(",
"\"stream is closed\"",
")",
"raise",
"StopIteration",
"(",
")",
"line",
"=",
"self",
".",
"readl... | Provides hook for Python2 iterator functionality. | [
"Provides",
"hook",
"for",
"Python2",
"iterator",
"functionality",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/streaming_client.py#L292-L304 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/streaming_client.py | StreamEncryptor.ciphertext_length | def ciphertext_length(self):
"""Returns the length of the resulting ciphertext message in bytes.
:rtype: int
"""
return aws_encryption_sdk.internal.formatting.ciphertext_length(
header=self.header, plaintext_length=self.stream_length
) | python | def ciphertext_length(self):
"""Returns the length of the resulting ciphertext message in bytes.
:rtype: int
"""
return aws_encryption_sdk.internal.formatting.ciphertext_length(
header=self.header, plaintext_length=self.stream_length
) | [
"def",
"ciphertext_length",
"(",
"self",
")",
":",
"return",
"aws_encryption_sdk",
".",
"internal",
".",
"formatting",
".",
"ciphertext_length",
"(",
"header",
"=",
"self",
".",
"header",
",",
"plaintext_length",
"=",
"self",
".",
"stream_length",
")"
] | Returns the length of the resulting ciphertext message in bytes.
:rtype: int | [
"Returns",
"the",
"length",
"of",
"the",
"resulting",
"ciphertext",
"message",
"in",
"bytes",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/streaming_client.py#L409-L416 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/streaming_client.py | StreamEncryptor._write_header | def _write_header(self):
"""Builds the message header and writes it to the output stream."""
self.output_buffer += serialize_header(header=self._header, signer=self.signer)
self.output_buffer += serialize_header_auth(
algorithm=self._encryption_materials.algorithm,
header... | python | def _write_header(self):
"""Builds the message header and writes it to the output stream."""
self.output_buffer += serialize_header(header=self._header, signer=self.signer)
self.output_buffer += serialize_header_auth(
algorithm=self._encryption_materials.algorithm,
header... | [
"def",
"_write_header",
"(",
"self",
")",
":",
"self",
".",
"output_buffer",
"+=",
"serialize_header",
"(",
"header",
"=",
"self",
".",
"_header",
",",
"signer",
"=",
"self",
".",
"signer",
")",
"self",
".",
"output_buffer",
"+=",
"serialize_header_auth",
"(... | Builds the message header and writes it to the output stream. | [
"Builds",
"the",
"message",
"header",
"and",
"writes",
"it",
"to",
"the",
"output",
"stream",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/streaming_client.py#L484-L492 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/streaming_client.py | StreamEncryptor._read_bytes_to_non_framed_body | def _read_bytes_to_non_framed_body(self, b):
"""Reads the requested number of bytes from source to a streaming non-framed message body.
:param int b: Number of bytes to read
:returns: Encrypted bytes from source stream
:rtype: bytes
"""
_LOGGER.debug("Reading %d bytes", ... | python | def _read_bytes_to_non_framed_body(self, b):
"""Reads the requested number of bytes from source to a streaming non-framed message body.
:param int b: Number of bytes to read
:returns: Encrypted bytes from source stream
:rtype: bytes
"""
_LOGGER.debug("Reading %d bytes", ... | [
"def",
"_read_bytes_to_non_framed_body",
"(",
"self",
",",
"b",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Reading %d bytes\"",
",",
"b",
")",
"plaintext",
"=",
"self",
".",
"__unframed_plaintext_cache",
".",
"read",
"(",
"b",
")",
"plaintext_length",
"=",
"le... | Reads the requested number of bytes from source to a streaming non-framed message body.
:param int b: Number of bytes to read
:returns: Encrypted bytes from source stream
:rtype: bytes | [
"Reads",
"the",
"requested",
"number",
"of",
"bytes",
"from",
"source",
"to",
"a",
"streaming",
"non",
"-",
"framed",
"message",
"body",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/streaming_client.py#L529-L562 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/streaming_client.py | StreamEncryptor._read_bytes_to_framed_body | def _read_bytes_to_framed_body(self, b):
"""Reads the requested number of bytes from source to a streaming framed message body.
:param int b: Number of bytes to read
:returns: Bytes read from source stream, encrypted, and serialized
:rtype: bytes
"""
_LOGGER.debug("colle... | python | def _read_bytes_to_framed_body(self, b):
"""Reads the requested number of bytes from source to a streaming framed message body.
:param int b: Number of bytes to read
:returns: Bytes read from source stream, encrypted, and serialized
:rtype: bytes
"""
_LOGGER.debug("colle... | [
"def",
"_read_bytes_to_framed_body",
"(",
"self",
",",
"b",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"collecting %d bytes\"",
",",
"b",
")",
"_b",
"=",
"b",
"if",
"b",
">",
"0",
":",
"_frames_to_read",
"=",
"math",
".",
"ceil",
"(",
"b",
"/",
"float",... | Reads the requested number of bytes from source to a streaming framed message body.
:param int b: Number of bytes to read
:returns: Bytes read from source stream, encrypted, and serialized
:rtype: bytes | [
"Reads",
"the",
"requested",
"number",
"of",
"bytes",
"from",
"source",
"to",
"a",
"streaming",
"framed",
"message",
"body",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/streaming_client.py#L564-L627 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/streaming_client.py | StreamDecryptor._read_header | def _read_header(self):
"""Reads the message header from the input stream.
:returns: tuple containing deserialized header and header_auth objects
:rtype: tuple of aws_encryption_sdk.structures.MessageHeader
and aws_encryption_sdk.internal.structures.MessageHeaderAuthentication
... | python | def _read_header(self):
"""Reads the message header from the input stream.
:returns: tuple containing deserialized header and header_auth objects
:rtype: tuple of aws_encryption_sdk.structures.MessageHeader
and aws_encryption_sdk.internal.structures.MessageHeaderAuthentication
... | [
"def",
"_read_header",
"(",
"self",
")",
":",
"header",
",",
"raw_header",
"=",
"deserialize_header",
"(",
"self",
".",
"source_stream",
")",
"self",
".",
"__unframed_bytes_read",
"+=",
"len",
"(",
"raw_header",
")",
"if",
"(",
"self",
".",
"config",
".",
... | Reads the message header from the input stream.
:returns: tuple containing deserialized header and header_auth objects
:rtype: tuple of aws_encryption_sdk.structures.MessageHeader
and aws_encryption_sdk.internal.structures.MessageHeaderAuthentication
:raises CustomMaximumValueExceed... | [
"Reads",
"the",
"message",
"header",
"from",
"the",
"input",
"stream",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/streaming_client.py#L738-L782 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/streaming_client.py | StreamDecryptor._read_bytes_from_non_framed_body | def _read_bytes_from_non_framed_body(self, b):
"""Reads the requested number of bytes from a streaming non-framed message body.
:param int b: Number of bytes to read
:returns: Decrypted bytes from source stream
:rtype: bytes
"""
_LOGGER.debug("starting non-framed body re... | python | def _read_bytes_from_non_framed_body(self, b):
"""Reads the requested number of bytes from a streaming non-framed message body.
:param int b: Number of bytes to read
:returns: Decrypted bytes from source stream
:rtype: bytes
"""
_LOGGER.debug("starting non-framed body re... | [
"def",
"_read_bytes_from_non_framed_body",
"(",
"self",
",",
"b",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"starting non-framed body read\"",
")",
"# Always read the entire message for non-framed message bodies.",
"bytes_to_read",
"=",
"self",
".",
"body_length",
"_LOGGER",
... | Reads the requested number of bytes from a streaming non-framed message body.
:param int b: Number of bytes to read
:returns: Decrypted bytes from source stream
:rtype: bytes | [
"Reads",
"the",
"requested",
"number",
"of",
"bytes",
"from",
"a",
"streaming",
"non",
"-",
"framed",
"message",
"body",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/streaming_client.py#L814-L857 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/streaming_client.py | StreamDecryptor._read_bytes_from_framed_body | def _read_bytes_from_framed_body(self, b):
"""Reads the requested number of bytes from a streaming framed message body.
:param int b: Number of bytes to read
:returns: Bytes read from source stream and decrypted
:rtype: bytes
"""
plaintext = b""
final_frame = Fal... | python | def _read_bytes_from_framed_body(self, b):
"""Reads the requested number of bytes from a streaming framed message body.
:param int b: Number of bytes to read
:returns: Bytes read from source stream and decrypted
:rtype: bytes
"""
plaintext = b""
final_frame = Fal... | [
"def",
"_read_bytes_from_framed_body",
"(",
"self",
",",
"b",
")",
":",
"plaintext",
"=",
"b\"\"",
"final_frame",
"=",
"False",
"_LOGGER",
".",
"debug",
"(",
"\"collecting %d bytes\"",
",",
"b",
")",
"while",
"len",
"(",
"plaintext",
")",
"<",
"b",
"and",
... | Reads the requested number of bytes from a streaming framed message body.
:param int b: Number of bytes to read
:returns: Bytes read from source stream and decrypted
:rtype: bytes | [
"Reads",
"the",
"requested",
"number",
"of",
"bytes",
"from",
"a",
"streaming",
"framed",
"message",
"body",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/streaming_client.py#L859-L899 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/streaming_client.py | StreamDecryptor.close | def close(self):
"""Closes out the stream."""
_LOGGER.debug("Closing stream")
if not hasattr(self, "footer"):
raise SerializationError("Footer not read")
super(StreamDecryptor, self).close() | python | def close(self):
"""Closes out the stream."""
_LOGGER.debug("Closing stream")
if not hasattr(self, "footer"):
raise SerializationError("Footer not read")
super(StreamDecryptor, self).close() | [
"def",
"close",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Closing stream\"",
")",
"if",
"not",
"hasattr",
"(",
"self",
",",
"\"footer\"",
")",
":",
"raise",
"SerializationError",
"(",
"\"Footer not read\"",
")",
"super",
"(",
"StreamDecryptor",
... | Closes out the stream. | [
"Closes",
"out",
"the",
"stream",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/streaming_client.py#L923-L928 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/key_providers/kms.py | _region_from_key_id | def _region_from_key_id(key_id, default_region=None):
"""Determine the target region from a key ID, falling back to a default region if provided.
:param str key_id: AWS KMS key ID
:param str default_region: Region to use if no region found in key_id
:returns: region name
:rtype: str
:raises Unk... | python | def _region_from_key_id(key_id, default_region=None):
"""Determine the target region from a key ID, falling back to a default region if provided.
:param str key_id: AWS KMS key ID
:param str default_region: Region to use if no region found in key_id
:returns: region name
:rtype: str
:raises Unk... | [
"def",
"_region_from_key_id",
"(",
"key_id",
",",
"default_region",
"=",
"None",
")",
":",
"try",
":",
"region_name",
"=",
"key_id",
".",
"split",
"(",
"\":\"",
",",
"4",
")",
"[",
"3",
"]",
"except",
"IndexError",
":",
"if",
"default_region",
"is",
"Non... | Determine the target region from a key ID, falling back to a default region if provided.
:param str key_id: AWS KMS key ID
:param str default_region: Region to use if no region found in key_id
:returns: region name
:rtype: str
:raises UnknownRegionError: if no region found in key_id and no default_... | [
"Determine",
"the",
"target",
"region",
"from",
"a",
"key",
"ID",
"falling",
"back",
"to",
"a",
"default",
"region",
"if",
"provided",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/key_providers/kms.py#L35-L52 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/key_providers/kms.py | KMSMasterKeyProvider._process_config | def _process_config(self):
"""Traverses the config and adds master keys and regional clients as needed."""
self._user_agent_adding_config = botocore.config.Config(user_agent_extra=USER_AGENT_SUFFIX)
if self.config.region_names:
self.add_regional_clients_from_list(self.config.region_... | python | def _process_config(self):
"""Traverses the config and adds master keys and regional clients as needed."""
self._user_agent_adding_config = botocore.config.Config(user_agent_extra=USER_AGENT_SUFFIX)
if self.config.region_names:
self.add_regional_clients_from_list(self.config.region_... | [
"def",
"_process_config",
"(",
"self",
")",
":",
"self",
".",
"_user_agent_adding_config",
"=",
"botocore",
".",
"config",
".",
"Config",
"(",
"user_agent_extra",
"=",
"USER_AGENT_SUFFIX",
")",
"if",
"self",
".",
"config",
".",
"region_names",
":",
"self",
"."... | Traverses the config and adds master keys and regional clients as needed. | [
"Traverses",
"the",
"config",
"and",
"adds",
"master",
"keys",
"and",
"regional",
"clients",
"as",
"needed",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/key_providers/kms.py#L115-L128 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/key_providers/kms.py | KMSMasterKeyProvider._wrap_client | def _wrap_client(self, region_name, method, *args, **kwargs):
"""Proxies all calls to a kms clients methods and removes misbehaving clients
:param str region_name: AWS Region ID (ex: us-east-1)
:param callable method: a method on the KMS client to proxy
:param tuple args: list of argume... | python | def _wrap_client(self, region_name, method, *args, **kwargs):
"""Proxies all calls to a kms clients methods and removes misbehaving clients
:param str region_name: AWS Region ID (ex: us-east-1)
:param callable method: a method on the KMS client to proxy
:param tuple args: list of argume... | [
"def",
"_wrap_client",
"(",
"self",
",",
"region_name",
",",
"method",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"return",
"method",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"except",
"botocore",
".",
"exceptions",
".",
... | Proxies all calls to a kms clients methods and removes misbehaving clients
:param str region_name: AWS Region ID (ex: us-east-1)
:param callable method: a method on the KMS client to proxy
:param tuple args: list of arguments to pass to the provided ``method``
:param dict kwargs: dicton... | [
"Proxies",
"all",
"calls",
"to",
"a",
"kms",
"clients",
"methods",
"and",
"removes",
"misbehaving",
"clients"
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/key_providers/kms.py#L130-L145 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/key_providers/kms.py | KMSMasterKeyProvider._register_client | def _register_client(self, client, region_name):
"""Uses functools.partial to wrap all methods on a client with the self._wrap_client method
:param botocore.client.BaseClient client: the client to proxy
:param str region_name: AWS Region ID (ex: us-east-1)
"""
for item in client... | python | def _register_client(self, client, region_name):
"""Uses functools.partial to wrap all methods on a client with the self._wrap_client method
:param botocore.client.BaseClient client: the client to proxy
:param str region_name: AWS Region ID (ex: us-east-1)
"""
for item in client... | [
"def",
"_register_client",
"(",
"self",
",",
"client",
",",
"region_name",
")",
":",
"for",
"item",
"in",
"client",
".",
"meta",
".",
"method_to_api_mapping",
":",
"method",
"=",
"getattr",
"(",
"client",
",",
"item",
")",
"wrapped_method",
"=",
"functools",... | Uses functools.partial to wrap all methods on a client with the self._wrap_client method
:param botocore.client.BaseClient client: the client to proxy
:param str region_name: AWS Region ID (ex: us-east-1) | [
"Uses",
"functools",
".",
"partial",
"to",
"wrap",
"all",
"methods",
"on",
"a",
"client",
"with",
"the",
"self",
".",
"_wrap_client",
"method"
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/key_providers/kms.py#L147-L156 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/key_providers/kms.py | KMSMasterKeyProvider.add_regional_client | def add_regional_client(self, region_name):
"""Adds a regional client for the specified region if it does not already exist.
:param str region_name: AWS Region ID (ex: us-east-1)
"""
if region_name not in self._regional_clients:
session = boto3.session.Session(region_name=re... | python | def add_regional_client(self, region_name):
"""Adds a regional client for the specified region if it does not already exist.
:param str region_name: AWS Region ID (ex: us-east-1)
"""
if region_name not in self._regional_clients:
session = boto3.session.Session(region_name=re... | [
"def",
"add_regional_client",
"(",
"self",
",",
"region_name",
")",
":",
"if",
"region_name",
"not",
"in",
"self",
".",
"_regional_clients",
":",
"session",
"=",
"boto3",
".",
"session",
".",
"Session",
"(",
"region_name",
"=",
"region_name",
",",
"botocore_se... | Adds a regional client for the specified region if it does not already exist.
:param str region_name: AWS Region ID (ex: us-east-1) | [
"Adds",
"a",
"regional",
"client",
"for",
"the",
"specified",
"region",
"if",
"it",
"does",
"not",
"already",
"exist",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/key_providers/kms.py#L158-L167 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/key_providers/kms.py | KMSMasterKeyProvider._client | def _client(self, key_id):
"""Returns a Boto3 KMS client for the appropriate region.
:param str key_id: KMS CMK ID
"""
region_name = _region_from_key_id(key_id, self.default_region)
self.add_regional_client(region_name)
return self._regional_clients[region_name] | python | def _client(self, key_id):
"""Returns a Boto3 KMS client for the appropriate region.
:param str key_id: KMS CMK ID
"""
region_name = _region_from_key_id(key_id, self.default_region)
self.add_regional_client(region_name)
return self._regional_clients[region_name] | [
"def",
"_client",
"(",
"self",
",",
"key_id",
")",
":",
"region_name",
"=",
"_region_from_key_id",
"(",
"key_id",
",",
"self",
".",
"default_region",
")",
"self",
".",
"add_regional_client",
"(",
"region_name",
")",
"return",
"self",
".",
"_regional_clients",
... | Returns a Boto3 KMS client for the appropriate region.
:param str key_id: KMS CMK ID | [
"Returns",
"a",
"Boto3",
"KMS",
"client",
"for",
"the",
"appropriate",
"region",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/key_providers/kms.py#L177-L184 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/key_providers/kms.py | KMSMasterKeyProvider._new_master_key | def _new_master_key(self, key_id):
"""Returns a KMSMasterKey for the specified key_id.
:param bytes key_id: KMS CMK ID
:returns: KMS Master Key based on key_id
:rtype: aws_encryption_sdk.key_providers.kms.KMSMasterKey
:raises InvalidKeyIdError: if key_id is not a valid KMS CMK I... | python | def _new_master_key(self, key_id):
"""Returns a KMSMasterKey for the specified key_id.
:param bytes key_id: KMS CMK ID
:returns: KMS Master Key based on key_id
:rtype: aws_encryption_sdk.key_providers.kms.KMSMasterKey
:raises InvalidKeyIdError: if key_id is not a valid KMS CMK I... | [
"def",
"_new_master_key",
"(",
"self",
",",
"key_id",
")",
":",
"_key_id",
"=",
"to_str",
"(",
"key_id",
")",
"# KMS client requires str, not bytes",
"return",
"KMSMasterKey",
"(",
"config",
"=",
"KMSMasterKeyConfig",
"(",
"key_id",
"=",
"key_id",
",",
"client",
... | Returns a KMSMasterKey for the specified key_id.
:param bytes key_id: KMS CMK ID
:returns: KMS Master Key based on key_id
:rtype: aws_encryption_sdk.key_providers.kms.KMSMasterKey
:raises InvalidKeyIdError: if key_id is not a valid KMS CMK ID to which this key provider has access | [
"Returns",
"a",
"KMSMasterKey",
"for",
"the",
"specified",
"key_id",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/key_providers/kms.py#L186-L195 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/key_providers/kms.py | KMSMasterKey._generate_data_key | def _generate_data_key(self, algorithm, encryption_context=None):
"""Generates data key and returns plaintext and ciphertext of key.
:param algorithm: Algorithm on which to base data key
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param dict encryption_context: Encryption... | python | def _generate_data_key(self, algorithm, encryption_context=None):
"""Generates data key and returns plaintext and ciphertext of key.
:param algorithm: Algorithm on which to base data key
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param dict encryption_context: Encryption... | [
"def",
"_generate_data_key",
"(",
"self",
",",
"algorithm",
",",
"encryption_context",
"=",
"None",
")",
":",
"kms_params",
"=",
"{",
"\"KeyId\"",
":",
"self",
".",
"_key_id",
",",
"\"NumberOfBytes\"",
":",
"algorithm",
".",
"kdf_input_len",
"}",
"if",
"encryp... | Generates data key and returns plaintext and ciphertext of key.
:param algorithm: Algorithm on which to base data key
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param dict encryption_context: Encryption context to pass to KMS
:returns: Generated data key
:rtype: ... | [
"Generates",
"data",
"key",
"and",
"returns",
"plaintext",
"and",
"ciphertext",
"of",
"key",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/key_providers/kms.py#L244-L272 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/key_providers/kms.py | KMSMasterKey._encrypt_data_key | def _encrypt_data_key(self, data_key, algorithm, encryption_context=None):
"""Encrypts a data key and returns the ciphertext.
:param data_key: Unencrypted data key
:type data_key: :class:`aws_encryption_sdk.structures.RawDataKey`
or :class:`aws_encryption_sdk.structures.DataKey`
... | python | def _encrypt_data_key(self, data_key, algorithm, encryption_context=None):
"""Encrypts a data key and returns the ciphertext.
:param data_key: Unencrypted data key
:type data_key: :class:`aws_encryption_sdk.structures.RawDataKey`
or :class:`aws_encryption_sdk.structures.DataKey`
... | [
"def",
"_encrypt_data_key",
"(",
"self",
",",
"data_key",
",",
"algorithm",
",",
"encryption_context",
"=",
"None",
")",
":",
"kms_params",
"=",
"{",
"\"KeyId\"",
":",
"self",
".",
"_key_id",
",",
"\"Plaintext\"",
":",
"data_key",
".",
"data_key",
"}",
"if",... | Encrypts a data key and returns the ciphertext.
:param data_key: Unencrypted data key
:type data_key: :class:`aws_encryption_sdk.structures.RawDataKey`
or :class:`aws_encryption_sdk.structures.DataKey`
:param algorithm: Placeholder to maintain API compatibility with parent
:... | [
"Encrypts",
"a",
"data",
"key",
"and",
"returns",
"the",
"ciphertext",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/key_providers/kms.py#L274-L302 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/serialize.py | serialize_encrypted_data_key | def serialize_encrypted_data_key(encrypted_data_key):
"""Serializes an encrypted data key.
.. versionadded:: 1.3.0
:param encrypted_data_key: Encrypted data key to serialize
:type encrypted_data_key: aws_encryption_sdk.structures.EncryptedDataKey
:returns: Serialized encrypted data key
:rtype:... | python | def serialize_encrypted_data_key(encrypted_data_key):
"""Serializes an encrypted data key.
.. versionadded:: 1.3.0
:param encrypted_data_key: Encrypted data key to serialize
:type encrypted_data_key: aws_encryption_sdk.structures.EncryptedDataKey
:returns: Serialized encrypted data key
:rtype:... | [
"def",
"serialize_encrypted_data_key",
"(",
"encrypted_data_key",
")",
":",
"encrypted_data_key_format",
"=",
"(",
"\">\"",
"# big endian",
"\"H\"",
"# key provider ID length",
"\"{provider_id_len}s\"",
"# key provider ID",
"\"H\"",
"# key info length",
"\"{provider_info_len}s\"",
... | Serializes an encrypted data key.
.. versionadded:: 1.3.0
:param encrypted_data_key: Encrypted data key to serialize
:type encrypted_data_key: aws_encryption_sdk.structures.EncryptedDataKey
:returns: Serialized encrypted data key
:rtype: bytes | [
"Serializes",
"an",
"encrypted",
"data",
"key",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/serialize.py#L29-L60 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/serialize.py | serialize_header | def serialize_header(header, signer=None):
"""Serializes a header object.
:param header: Header to serialize
:type header: aws_encryption_sdk.structures.MessageHeader
:param signer: Cryptographic signer object (optional)
:type signer: aws_encryption_sdk.internal.crypto.Signer
:returns: Serializ... | python | def serialize_header(header, signer=None):
"""Serializes a header object.
:param header: Header to serialize
:type header: aws_encryption_sdk.structures.MessageHeader
:param signer: Cryptographic signer object (optional)
:type signer: aws_encryption_sdk.internal.crypto.Signer
:returns: Serializ... | [
"def",
"serialize_header",
"(",
"header",
",",
"signer",
"=",
"None",
")",
":",
"ec_serialized",
"=",
"aws_encryption_sdk",
".",
"internal",
".",
"formatting",
".",
"encryption_context",
".",
"serialize_encryption_context",
"(",
"header",
".",
"encryption_context",
... | Serializes a header object.
:param header: Header to serialize
:type header: aws_encryption_sdk.structures.MessageHeader
:param signer: Cryptographic signer object (optional)
:type signer: aws_encryption_sdk.internal.crypto.Signer
:returns: Serialized header
:rtype: bytes | [
"Serializes",
"a",
"header",
"object",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/serialize.py#L63-L118 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/serialize.py | serialize_header_auth | def serialize_header_auth(algorithm, header, data_encryption_key, signer=None):
"""Creates serialized header authentication data.
:param algorithm: Algorithm to use for encryption
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes header: Serialized message header
:param bytes d... | python | def serialize_header_auth(algorithm, header, data_encryption_key, signer=None):
"""Creates serialized header authentication data.
:param algorithm: Algorithm to use for encryption
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes header: Serialized message header
:param bytes d... | [
"def",
"serialize_header_auth",
"(",
"algorithm",
",",
"header",
",",
"data_encryption_key",
",",
"signer",
"=",
"None",
")",
":",
"header_auth",
"=",
"encrypt",
"(",
"algorithm",
"=",
"algorithm",
",",
"key",
"=",
"data_encryption_key",
",",
"plaintext",
"=",
... | Creates serialized header authentication data.
:param algorithm: Algorithm to use for encryption
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes header: Serialized message header
:param bytes data_encryption_key: Data key with which to encrypt message
:param signer: Cryptogra... | [
"Creates",
"serialized",
"header",
"authentication",
"data",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/serialize.py#L121-L147 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/serialize.py | serialize_non_framed_open | def serialize_non_framed_open(algorithm, iv, plaintext_length, signer=None):
"""Serializes the opening block for a non-framed message body.
:param algorithm: Algorithm to use for encryption
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes iv: IV value used to encrypt body
:par... | python | def serialize_non_framed_open(algorithm, iv, plaintext_length, signer=None):
"""Serializes the opening block for a non-framed message body.
:param algorithm: Algorithm to use for encryption
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes iv: IV value used to encrypt body
:par... | [
"def",
"serialize_non_framed_open",
"(",
"algorithm",
",",
"iv",
",",
"plaintext_length",
",",
"signer",
"=",
"None",
")",
":",
"body_start_format",
"=",
"(",
"\">\"",
"\"{iv_length}s\"",
"\"Q\"",
")",
".",
"format",
"(",
"iv_length",
"=",
"algorithm",
".",
"i... | Serializes the opening block for a non-framed message body.
:param algorithm: Algorithm to use for encryption
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes iv: IV value used to encrypt body
:param int plaintext_length: Length of plaintext (and thus ciphertext) in body
:para... | [
"Serializes",
"the",
"opening",
"block",
"for",
"a",
"non",
"-",
"framed",
"message",
"body",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/serialize.py#L150-L166 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/serialize.py | serialize_non_framed_close | def serialize_non_framed_close(tag, signer=None):
"""Serializes the closing block for a non-framed message body.
:param bytes tag: Auth tag value from body encryptor
:param signer: Cryptographic signer object (optional)
:type signer: aws_encryption_sdk.internal.crypto.Signer
:returns: Serialized bo... | python | def serialize_non_framed_close(tag, signer=None):
"""Serializes the closing block for a non-framed message body.
:param bytes tag: Auth tag value from body encryptor
:param signer: Cryptographic signer object (optional)
:type signer: aws_encryption_sdk.internal.crypto.Signer
:returns: Serialized bo... | [
"def",
"serialize_non_framed_close",
"(",
"tag",
",",
"signer",
"=",
"None",
")",
":",
"body_close",
"=",
"struct",
".",
"pack",
"(",
"\"{auth_len}s\"",
".",
"format",
"(",
"auth_len",
"=",
"len",
"(",
"tag",
")",
")",
",",
"tag",
")",
"if",
"signer",
... | Serializes the closing block for a non-framed message body.
:param bytes tag: Auth tag value from body encryptor
:param signer: Cryptographic signer object (optional)
:type signer: aws_encryption_sdk.internal.crypto.Signer
:returns: Serialized body close block
:rtype: bytes | [
"Serializes",
"the",
"closing",
"block",
"for",
"a",
"non",
"-",
"framed",
"message",
"body",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/serialize.py#L169-L181 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/serialize.py | serialize_frame | def serialize_frame(
algorithm, plaintext, message_id, data_encryption_key, frame_length, sequence_number, is_final_frame, signer=None
):
"""Receives a message plaintext, breaks off a frame, encrypts and serializes
the frame, and returns the encrypted frame and the remaining plaintext.
:param algorithm... | python | def serialize_frame(
algorithm, plaintext, message_id, data_encryption_key, frame_length, sequence_number, is_final_frame, signer=None
):
"""Receives a message plaintext, breaks off a frame, encrypts and serializes
the frame, and returns the encrypted frame and the remaining plaintext.
:param algorithm... | [
"def",
"serialize_frame",
"(",
"algorithm",
",",
"plaintext",
",",
"message_id",
",",
"data_encryption_key",
",",
"frame_length",
",",
"sequence_number",
",",
"is_final_frame",
",",
"signer",
"=",
"None",
")",
":",
"if",
"sequence_number",
"<",
"1",
":",
"raise"... | Receives a message plaintext, breaks off a frame, encrypts and serializes
the frame, and returns the encrypted frame and the remaining plaintext.
:param algorithm: Algorithm to use for encryption
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes plaintext: Source plaintext to encry... | [
"Receives",
"a",
"message",
"plaintext",
"breaks",
"off",
"a",
"frame",
"encrypts",
"and",
"serializes",
"the",
"frame",
"and",
"returns",
"the",
"encrypted",
"frame",
"and",
"the",
"remaining",
"plaintext",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/serialize.py#L184-L252 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/serialize.py | serialize_footer | def serialize_footer(signer):
"""Uses the signer object which has been used to sign the message to generate
the signature, then serializes that signature.
:param signer: Cryptographic signer object
:type signer: aws_encryption_sdk.internal.crypto.Signer
:returns: Serialized footer
:rtype: bytes... | python | def serialize_footer(signer):
"""Uses the signer object which has been used to sign the message to generate
the signature, then serializes that signature.
:param signer: Cryptographic signer object
:type signer: aws_encryption_sdk.internal.crypto.Signer
:returns: Serialized footer
:rtype: bytes... | [
"def",
"serialize_footer",
"(",
"signer",
")",
":",
"footer",
"=",
"b\"\"",
"if",
"signer",
"is",
"not",
"None",
":",
"signature",
"=",
"signer",
".",
"finalize",
"(",
")",
"footer",
"=",
"struct",
".",
"pack",
"(",
"\">H{sig_len}s\"",
".",
"format",
"("... | Uses the signer object which has been used to sign the message to generate
the signature, then serializes that signature.
:param signer: Cryptographic signer object
:type signer: aws_encryption_sdk.internal.crypto.Signer
:returns: Serialized footer
:rtype: bytes | [
"Uses",
"the",
"signer",
"object",
"which",
"has",
"been",
"used",
"to",
"sign",
"the",
"message",
"to",
"generate",
"the",
"signature",
"then",
"serializes",
"that",
"signature",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/serialize.py#L255-L268 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/serialize.py | serialize_raw_master_key_prefix | def serialize_raw_master_key_prefix(raw_master_key):
"""Produces the prefix that a RawMasterKey will always use for the
key_info value of keys which require additional information.
:param raw_master_key: RawMasterKey for which to produce a prefix
:type raw_master_key: aws_encryption_sdk.key_providers.r... | python | def serialize_raw_master_key_prefix(raw_master_key):
"""Produces the prefix that a RawMasterKey will always use for the
key_info value of keys which require additional information.
:param raw_master_key: RawMasterKey for which to produce a prefix
:type raw_master_key: aws_encryption_sdk.key_providers.r... | [
"def",
"serialize_raw_master_key_prefix",
"(",
"raw_master_key",
")",
":",
"if",
"raw_master_key",
".",
"config",
".",
"wrapping_key",
".",
"wrapping_algorithm",
".",
"encryption_type",
"is",
"EncryptionType",
".",
"ASYMMETRIC",
":",
"return",
"to_bytes",
"(",
"raw_ma... | Produces the prefix that a RawMasterKey will always use for the
key_info value of keys which require additional information.
:param raw_master_key: RawMasterKey for which to produce a prefix
:type raw_master_key: aws_encryption_sdk.key_providers.raw.RawMasterKey
:returns: Serialized key_info prefix
... | [
"Produces",
"the",
"prefix",
"that",
"a",
"RawMasterKey",
"will",
"always",
"use",
"for",
"the",
"key_info",
"value",
"of",
"keys",
"which",
"require",
"additional",
"information",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/serialize.py#L271-L288 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/serialize.py | serialize_wrapped_key | def serialize_wrapped_key(key_provider, wrapping_algorithm, wrapping_key_id, encrypted_wrapped_key):
"""Serializes EncryptedData into a Wrapped EncryptedDataKey.
:param key_provider: Info for Wrapping MasterKey
:type key_provider: aws_encryption_sdk.structures.MasterKeyInfo
:param wrapping_algorithm: W... | python | def serialize_wrapped_key(key_provider, wrapping_algorithm, wrapping_key_id, encrypted_wrapped_key):
"""Serializes EncryptedData into a Wrapped EncryptedDataKey.
:param key_provider: Info for Wrapping MasterKey
:type key_provider: aws_encryption_sdk.structures.MasterKeyInfo
:param wrapping_algorithm: W... | [
"def",
"serialize_wrapped_key",
"(",
"key_provider",
",",
"wrapping_algorithm",
",",
"wrapping_key_id",
",",
"encrypted_wrapped_key",
")",
":",
"if",
"encrypted_wrapped_key",
".",
"iv",
"is",
"None",
":",
"key_info",
"=",
"wrapping_key_id",
"key_ciphertext",
"=",
"enc... | Serializes EncryptedData into a Wrapped EncryptedDataKey.
:param key_provider: Info for Wrapping MasterKey
:type key_provider: aws_encryption_sdk.structures.MasterKeyInfo
:param wrapping_algorithm: Wrapping Algorithm with which to wrap plaintext_data_key
:type wrapping_algorithm: aws_encryption_sdk.ide... | [
"Serializes",
"EncryptedData",
"into",
"a",
"Wrapped",
"EncryptedDataKey",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/serialize.py#L291-L321 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/encryption_context.py | assemble_content_aad | def assemble_content_aad(message_id, aad_content_string, seq_num, length):
"""Assembles the Body AAD string for a message body structure.
:param message_id: Message ID
:type message_id: str
:param aad_content_string: ContentAADString object for frame type
:type aad_content_string: aws_encryption_sd... | python | def assemble_content_aad(message_id, aad_content_string, seq_num, length):
"""Assembles the Body AAD string for a message body structure.
:param message_id: Message ID
:type message_id: str
:param aad_content_string: ContentAADString object for frame type
:type aad_content_string: aws_encryption_sd... | [
"def",
"assemble_content_aad",
"(",
"message_id",
",",
"aad_content_string",
",",
"seq_num",
",",
"length",
")",
":",
"if",
"not",
"isinstance",
"(",
"aad_content_string",
",",
"aws_encryption_sdk",
".",
"identifiers",
".",
"ContentAADString",
")",
":",
"raise",
"... | Assembles the Body AAD string for a message body structure.
:param message_id: Message ID
:type message_id: str
:param aad_content_string: ContentAADString object for frame type
:type aad_content_string: aws_encryption_sdk.identifiers.ContentAADString
:param seq_num: Sequence number of frame
:t... | [
"Assembles",
"the",
"Body",
"AAD",
"string",
"for",
"a",
"message",
"body",
"structure",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/encryption_context.py#L29-L47 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/encryption_context.py | serialize_encryption_context | def serialize_encryption_context(encryption_context):
"""Serializes the contents of a dictionary into a byte string.
:param dict encryption_context: Dictionary of encrytion context keys/values.
:returns: Serialized encryption context
:rtype: bytes
"""
if not encryption_context:
return b... | python | def serialize_encryption_context(encryption_context):
"""Serializes the contents of a dictionary into a byte string.
:param dict encryption_context: Dictionary of encrytion context keys/values.
:returns: Serialized encryption context
:rtype: bytes
"""
if not encryption_context:
return b... | [
"def",
"serialize_encryption_context",
"(",
"encryption_context",
")",
":",
"if",
"not",
"encryption_context",
":",
"return",
"bytes",
"(",
")",
"serialized_context",
"=",
"bytearray",
"(",
")",
"dict_size",
"=",
"len",
"(",
"encryption_context",
")",
"if",
"dict_... | Serializes the contents of a dictionary into a byte string.
:param dict encryption_context: Dictionary of encrytion context keys/values.
:returns: Serialized encryption context
:rtype: bytes | [
"Serializes",
"the",
"contents",
"of",
"a",
"dictionary",
"into",
"a",
"byte",
"string",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/encryption_context.py#L50-L96 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/encryption_context.py | read_short | def read_short(source, offset):
"""Reads a number from a byte array.
:param bytes source: Source byte string
:param int offset: Point in byte string to start reading
:returns: Read number and offset at point after read data
:rtype: tuple of ints
:raises: SerializationError if unable to unpack
... | python | def read_short(source, offset):
"""Reads a number from a byte array.
:param bytes source: Source byte string
:param int offset: Point in byte string to start reading
:returns: Read number and offset at point after read data
:rtype: tuple of ints
:raises: SerializationError if unable to unpack
... | [
"def",
"read_short",
"(",
"source",
",",
"offset",
")",
":",
"try",
":",
"(",
"short",
",",
")",
"=",
"struct",
".",
"unpack_from",
"(",
"\">H\"",
",",
"source",
",",
"offset",
")",
"return",
"short",
",",
"offset",
"+",
"struct",
".",
"calcsize",
"(... | Reads a number from a byte array.
:param bytes source: Source byte string
:param int offset: Point in byte string to start reading
:returns: Read number and offset at point after read data
:rtype: tuple of ints
:raises: SerializationError if unable to unpack | [
"Reads",
"a",
"number",
"from",
"a",
"byte",
"array",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/encryption_context.py#L99-L112 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/encryption_context.py | read_string | def read_string(source, offset, length):
"""Reads a string from a byte string.
:param bytes source: Source byte string
:param int offset: Point in byte string to start reading
:param int length: Length of string to read
:returns: Read string and offset at point after read data
:rtype: tuple of ... | python | def read_string(source, offset, length):
"""Reads a string from a byte string.
:param bytes source: Source byte string
:param int offset: Point in byte string to start reading
:param int length: Length of string to read
:returns: Read string and offset at point after read data
:rtype: tuple of ... | [
"def",
"read_string",
"(",
"source",
",",
"offset",
",",
"length",
")",
":",
"end",
"=",
"offset",
"+",
"length",
"try",
":",
"return",
"(",
"codecs",
".",
"decode",
"(",
"source",
"[",
"offset",
":",
"end",
"]",
",",
"aws_encryption_sdk",
".",
"intern... | Reads a string from a byte string.
:param bytes source: Source byte string
:param int offset: Point in byte string to start reading
:param int length: Length of string to read
:returns: Read string and offset at point after read data
:rtype: tuple of str and int
:raises SerializationError: if u... | [
"Reads",
"a",
"string",
"from",
"a",
"byte",
"string",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/encryption_context.py#L115-L129 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/encryption_context.py | deserialize_encryption_context | def deserialize_encryption_context(serialized_encryption_context):
"""Deserializes the contents of a byte string into a dictionary.
:param bytes serialized_encryption_context: Source byte string containing serialized dictionary
:returns: Deserialized encryption context
:rtype: dict
:raises Serializ... | python | def deserialize_encryption_context(serialized_encryption_context):
"""Deserializes the contents of a byte string into a dictionary.
:param bytes serialized_encryption_context: Source byte string containing serialized dictionary
:returns: Deserialized encryption context
:rtype: dict
:raises Serializ... | [
"def",
"deserialize_encryption_context",
"(",
"serialized_encryption_context",
")",
":",
"if",
"len",
"(",
"serialized_encryption_context",
")",
">",
"aws_encryption_sdk",
".",
"internal",
".",
"defaults",
".",
"MAX_BYTE_ARRAY_SIZE",
":",
"raise",
"SerializationError",
"(... | Deserializes the contents of a byte string into a dictionary.
:param bytes serialized_encryption_context: Source byte string containing serialized dictionary
:returns: Deserialized encryption context
:rtype: dict
:raises SerializationError: if serialized encryption context is too large
:raises Seri... | [
"Deserializes",
"the",
"contents",
"of",
"a",
"byte",
"string",
"into",
"a",
"dictionary",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/encryption_context.py#L132-L170 | train |
aws/aws-encryption-sdk-python | decrypt_oracle/src/aws_encryption_sdk_decrypt_oracle/key_providers/null.py | NullMasterKey.owns_data_key | def owns_data_key(self, data_key: DataKey) -> bool:
"""Determine whether the data key is owned by a ``null`` or ``zero`` provider.
:param data_key: Data key to evaluate
:type data_key: :class:`aws_encryption_sdk.structures.DataKey`,
:class:`aws_encryption_sdk.structures.RawDataKey`,... | python | def owns_data_key(self, data_key: DataKey) -> bool:
"""Determine whether the data key is owned by a ``null`` or ``zero`` provider.
:param data_key: Data key to evaluate
:type data_key: :class:`aws_encryption_sdk.structures.DataKey`,
:class:`aws_encryption_sdk.structures.RawDataKey`,... | [
"def",
"owns_data_key",
"(",
"self",
",",
"data_key",
":",
"DataKey",
")",
"->",
"bool",
":",
"return",
"data_key",
".",
"key_provider",
".",
"provider_id",
"in",
"self",
".",
"_allowed_provider_ids"
] | Determine whether the data key is owned by a ``null`` or ``zero`` provider.
:param data_key: Data key to evaluate
:type data_key: :class:`aws_encryption_sdk.structures.DataKey`,
:class:`aws_encryption_sdk.structures.RawDataKey`,
or :class:`aws_encryption_sdk.structures.Encrypted... | [
"Determine",
"whether",
"the",
"data",
"key",
"is",
"owned",
"by",
"a",
"null",
"or",
"zero",
"provider",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/decrypt_oracle/src/aws_encryption_sdk_decrypt_oracle/key_providers/null.py#L46-L56 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/crypto/iv.py | frame_iv | def frame_iv(algorithm, sequence_number):
"""Builds the deterministic IV for a body frame.
:param algorithm: Algorithm for which to build IV
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param int sequence_number: Frame sequence number
:returns: Generated IV
:rtype: bytes
:rais... | python | def frame_iv(algorithm, sequence_number):
"""Builds the deterministic IV for a body frame.
:param algorithm: Algorithm for which to build IV
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param int sequence_number: Frame sequence number
:returns: Generated IV
:rtype: bytes
:rais... | [
"def",
"frame_iv",
"(",
"algorithm",
",",
"sequence_number",
")",
":",
"if",
"sequence_number",
"<",
"1",
"or",
"sequence_number",
">",
"MAX_FRAME_COUNT",
":",
"raise",
"ActionNotAllowedError",
"(",
"\"Invalid frame sequence number: {actual}\\nMust be between 1 and {max}\"",
... | Builds the deterministic IV for a body frame.
:param algorithm: Algorithm for which to build IV
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param int sequence_number: Frame sequence number
:returns: Generated IV
:rtype: bytes
:raises ActionNotAllowedError: if sequence number of o... | [
"Builds",
"the",
"deterministic",
"IV",
"for",
"a",
"body",
"frame",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/crypto/iv.py#L46-L64 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/identifiers.py | EncryptionSuite.valid_kdf | def valid_kdf(self, kdf):
"""Determine whether a KDFSuite can be used with this EncryptionSuite.
:param kdf: KDFSuite to evaluate
:type kdf: aws_encryption_sdk.identifiers.KDFSuite
:rtype: bool
"""
if kdf.input_length is None:
return True
if self.dat... | python | def valid_kdf(self, kdf):
"""Determine whether a KDFSuite can be used with this EncryptionSuite.
:param kdf: KDFSuite to evaluate
:type kdf: aws_encryption_sdk.identifiers.KDFSuite
:rtype: bool
"""
if kdf.input_length is None:
return True
if self.dat... | [
"def",
"valid_kdf",
"(",
"self",
",",
"kdf",
")",
":",
"if",
"kdf",
".",
"input_length",
"is",
"None",
":",
"return",
"True",
"if",
"self",
".",
"data_key_length",
">",
"kdf",
".",
"input_length",
"(",
"self",
")",
":",
"raise",
"InvalidAlgorithmError",
... | Determine whether a KDFSuite can be used with this EncryptionSuite.
:param kdf: KDFSuite to evaluate
:type kdf: aws_encryption_sdk.identifiers.KDFSuite
:rtype: bool | [
"Determine",
"whether",
"a",
"KDFSuite",
"can",
"be",
"used",
"with",
"this",
"EncryptionSuite",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/identifiers.py#L63-L78 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/__init__.py | header_length | def header_length(header):
"""Calculates the ciphertext message header length, given a complete header.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:rtype: int
"""
# Because encrypted data key lengths may not be knowable until the ciph... | python | def header_length(header):
"""Calculates the ciphertext message header length, given a complete header.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:rtype: int
"""
# Because encrypted data key lengths may not be knowable until the ciph... | [
"def",
"header_length",
"(",
"header",
")",
":",
"# Because encrypted data key lengths may not be knowable until the ciphertext",
"# is received from the providers, just serialize the header directly.",
"header_length",
"=",
"len",
"(",
"serialize_header",
"(",
"header",
")",
")",
... | Calculates the ciphertext message header length, given a complete header.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:rtype: int | [
"Calculates",
"the",
"ciphertext",
"message",
"header",
"length",
"given",
"a",
"complete",
"header",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/__init__.py#L17-L29 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/__init__.py | _non_framed_body_length | def _non_framed_body_length(header, plaintext_length):
"""Calculates the length of a non-framed message body, given a complete header.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:param int plaintext_length: Length of plaintext in bytes
:r... | python | def _non_framed_body_length(header, plaintext_length):
"""Calculates the length of a non-framed message body, given a complete header.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:param int plaintext_length: Length of plaintext in bytes
:r... | [
"def",
"_non_framed_body_length",
"(",
"header",
",",
"plaintext_length",
")",
":",
"body_length",
"=",
"header",
".",
"algorithm",
".",
"iv_len",
"# IV",
"body_length",
"+=",
"8",
"# Encrypted Content Length",
"body_length",
"+=",
"plaintext_length",
"# Encrypted Conte... | Calculates the length of a non-framed message body, given a complete header.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:param int plaintext_length: Length of plaintext in bytes
:rtype: int | [
"Calculates",
"the",
"length",
"of",
"a",
"non",
"-",
"framed",
"message",
"body",
"given",
"a",
"complete",
"header",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/__init__.py#L32-L44 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/__init__.py | _standard_frame_length | def _standard_frame_length(header):
"""Calculates the length of a standard ciphertext frame, given a complete header.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:rtype: int
"""
frame_length = 4 # Sequence Number
frame_length += h... | python | def _standard_frame_length(header):
"""Calculates the length of a standard ciphertext frame, given a complete header.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:rtype: int
"""
frame_length = 4 # Sequence Number
frame_length += h... | [
"def",
"_standard_frame_length",
"(",
"header",
")",
":",
"frame_length",
"=",
"4",
"# Sequence Number",
"frame_length",
"+=",
"header",
".",
"algorithm",
".",
"iv_len",
"# IV",
"frame_length",
"+=",
"header",
".",
"frame_length",
"# Encrypted Content",
"frame_length"... | Calculates the length of a standard ciphertext frame, given a complete header.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:rtype: int | [
"Calculates",
"the",
"length",
"of",
"a",
"standard",
"ciphertext",
"frame",
"given",
"a",
"complete",
"header",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/__init__.py#L47-L58 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/__init__.py | _final_frame_length | def _final_frame_length(header, final_frame_bytes):
"""Calculates the length of a final ciphertext frame, given a complete header
and the number of bytes of ciphertext in the final frame.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:param ... | python | def _final_frame_length(header, final_frame_bytes):
"""Calculates the length of a final ciphertext frame, given a complete header
and the number of bytes of ciphertext in the final frame.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:param ... | [
"def",
"_final_frame_length",
"(",
"header",
",",
"final_frame_bytes",
")",
":",
"final_frame_length",
"=",
"4",
"# Sequence Number End",
"final_frame_length",
"+=",
"4",
"# Sequence Number",
"final_frame_length",
"+=",
"header",
".",
"algorithm",
".",
"iv_len",
"# IV",... | Calculates the length of a final ciphertext frame, given a complete header
and the number of bytes of ciphertext in the final frame.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:param int final_frame_bytes: Bytes of ciphertext in the final fra... | [
"Calculates",
"the",
"length",
"of",
"a",
"final",
"ciphertext",
"frame",
"given",
"a",
"complete",
"header",
"and",
"the",
"number",
"of",
"bytes",
"of",
"ciphertext",
"in",
"the",
"final",
"frame",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/__init__.py#L61-L76 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/__init__.py | body_length | def body_length(header, plaintext_length):
"""Calculates the ciphertext message body length, given a complete header.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:param int plaintext_length: Length of plaintext in bytes
:rtype: int
"""... | python | def body_length(header, plaintext_length):
"""Calculates the ciphertext message body length, given a complete header.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:param int plaintext_length: Length of plaintext in bytes
:rtype: int
"""... | [
"def",
"body_length",
"(",
"header",
",",
"plaintext_length",
")",
":",
"body_length",
"=",
"0",
"if",
"header",
".",
"frame_length",
"==",
"0",
":",
"# Non-framed",
"body_length",
"+=",
"_non_framed_body_length",
"(",
"header",
",",
"plaintext_length",
")",
"el... | Calculates the ciphertext message body length, given a complete header.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:param int plaintext_length: Length of plaintext in bytes
:rtype: int | [
"Calculates",
"the",
"ciphertext",
"message",
"body",
"length",
"given",
"a",
"complete",
"header",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/__init__.py#L79-L94 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/__init__.py | footer_length | def footer_length(header):
"""Calculates the ciphertext message footer length, given a complete header.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:rtype: int
"""
footer_length = 0
if header.algorithm.signing_algorithm_info is not... | python | def footer_length(header):
"""Calculates the ciphertext message footer length, given a complete header.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:rtype: int
"""
footer_length = 0
if header.algorithm.signing_algorithm_info is not... | [
"def",
"footer_length",
"(",
"header",
")",
":",
"footer_length",
"=",
"0",
"if",
"header",
".",
"algorithm",
".",
"signing_algorithm_info",
"is",
"not",
"None",
":",
"footer_length",
"+=",
"2",
"# Signature Length",
"footer_length",
"+=",
"header",
".",
"algori... | Calculates the ciphertext message footer length, given a complete header.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:rtype: int | [
"Calculates",
"the",
"ciphertext",
"message",
"footer",
"length",
"given",
"a",
"complete",
"header",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/__init__.py#L97-L108 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/__init__.py | ciphertext_length | def ciphertext_length(header, plaintext_length):
"""Calculates the complete ciphertext message length, given a complete header.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:param int plaintext_length: Length of plaintext in bytes
:rtype: i... | python | def ciphertext_length(header, plaintext_length):
"""Calculates the complete ciphertext message length, given a complete header.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:param int plaintext_length: Length of plaintext in bytes
:rtype: i... | [
"def",
"ciphertext_length",
"(",
"header",
",",
"plaintext_length",
")",
":",
"ciphertext_length",
"=",
"header_length",
"(",
"header",
")",
"ciphertext_length",
"+=",
"body_length",
"(",
"header",
",",
"plaintext_length",
")",
"ciphertext_length",
"+=",
"footer_lengt... | Calculates the complete ciphertext message length, given a complete header.
:param header: Complete message header object
:type header: aws_encryption_sdk.structures.MessageHeader
:param int plaintext_length: Length of plaintext in bytes
:rtype: int | [
"Calculates",
"the",
"complete",
"ciphertext",
"message",
"length",
"given",
"a",
"complete",
"header",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/__init__.py#L111-L122 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/key_providers/raw.py | RawMasterKey.owns_data_key | def owns_data_key(self, data_key):
"""Determines if data_key object is owned by this RawMasterKey.
:param data_key: Data key to evaluate
:type data_key: :class:`aws_encryption_sdk.structures.DataKey`,
:class:`aws_encryption_sdk.structures.RawDataKey`,
or :class:`aws_encr... | python | def owns_data_key(self, data_key):
"""Determines if data_key object is owned by this RawMasterKey.
:param data_key: Data key to evaluate
:type data_key: :class:`aws_encryption_sdk.structures.DataKey`,
:class:`aws_encryption_sdk.structures.RawDataKey`,
or :class:`aws_encr... | [
"def",
"owns_data_key",
"(",
"self",
",",
"data_key",
")",
":",
"expected_key_info_len",
"=",
"-",
"1",
"if",
"(",
"self",
".",
"config",
".",
"wrapping_key",
".",
"wrapping_algorithm",
".",
"encryption_type",
"is",
"EncryptionType",
".",
"ASYMMETRIC",
"and",
... | Determines if data_key object is owned by this RawMasterKey.
:param data_key: Data key to evaluate
:type data_key: :class:`aws_encryption_sdk.structures.DataKey`,
:class:`aws_encryption_sdk.structures.RawDataKey`,
or :class:`aws_encryption_sdk.structures.EncryptedDataKey`
... | [
"Determines",
"if",
"data_key",
"object",
"is",
"owned",
"by",
"this",
"RawMasterKey",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/key_providers/raw.py#L75-L113 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/key_providers/raw.py | RawMasterKey._encrypt_data_key | def _encrypt_data_key(self, data_key, algorithm, encryption_context):
"""Performs the provider-specific key encryption actions.
:param data_key: Unencrypted data key
:type data_key: :class:`aws_encryption_sdk.structures.RawDataKey`
or :class:`aws_encryption_sdk.structures.DataKey`
... | python | def _encrypt_data_key(self, data_key, algorithm, encryption_context):
"""Performs the provider-specific key encryption actions.
:param data_key: Unencrypted data key
:type data_key: :class:`aws_encryption_sdk.structures.RawDataKey`
or :class:`aws_encryption_sdk.structures.DataKey`
... | [
"def",
"_encrypt_data_key",
"(",
"self",
",",
"data_key",
",",
"algorithm",
",",
"encryption_context",
")",
":",
"# Raw key string to EncryptedData",
"encrypted_wrapped_key",
"=",
"self",
".",
"config",
".",
"wrapping_key",
".",
"encrypt",
"(",
"plaintext_data_key",
"... | Performs the provider-specific key encryption actions.
:param data_key: Unencrypted data key
:type data_key: :class:`aws_encryption_sdk.structures.RawDataKey`
or :class:`aws_encryption_sdk.structures.DataKey`
:param algorithm: Algorithm object which directs how this Master Key will ... | [
"Performs",
"the",
"provider",
"-",
"specific",
"key",
"encryption",
"actions",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/key_providers/raw.py#L136-L159 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/caches/null.py | NullCryptoMaterialsCache.put_encryption_materials | def put_encryption_materials(self, cache_key, encryption_materials, plaintext_length, entry_hints=None):
"""Does not add encryption materials to the cache since there is no cache to which to add them.
:param bytes cache_key: Identifier for entries in cache
:param encryption_materials: Encryptio... | python | def put_encryption_materials(self, cache_key, encryption_materials, plaintext_length, entry_hints=None):
"""Does not add encryption materials to the cache since there is no cache to which to add them.
:param bytes cache_key: Identifier for entries in cache
:param encryption_materials: Encryptio... | [
"def",
"put_encryption_materials",
"(",
"self",
",",
"cache_key",
",",
"encryption_materials",
",",
"plaintext_length",
",",
"entry_hints",
"=",
"None",
")",
":",
"return",
"CryptoMaterialsCacheEntry",
"(",
"cache_key",
"=",
"cache_key",
",",
"value",
"=",
"encrypti... | Does not add encryption materials to the cache since there is no cache to which to add them.
:param bytes cache_key: Identifier for entries in cache
:param encryption_materials: Encryption materials to add to cache
:type encryption_materials: aws_encryption_sdk.materials_managers.EncryptionMate... | [
"Does",
"not",
"add",
"encryption",
"materials",
"to",
"the",
"cache",
"since",
"there",
"is",
"no",
"cache",
"to",
"which",
"to",
"add",
"them",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/caches/null.py#L25-L36 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/crypto/authentication.py | _PrehashingAuthenticator._set_signature_type | def _set_signature_type(self):
"""Ensures that the algorithm signature type is a known type and sets a reference value."""
try:
verify_interface(ec.EllipticCurve, self.algorithm.signing_algorithm_info)
return ec.EllipticCurve
except InterfaceNotImplemented:
ra... | python | def _set_signature_type(self):
"""Ensures that the algorithm signature type is a known type and sets a reference value."""
try:
verify_interface(ec.EllipticCurve, self.algorithm.signing_algorithm_info)
return ec.EllipticCurve
except InterfaceNotImplemented:
ra... | [
"def",
"_set_signature_type",
"(",
"self",
")",
":",
"try",
":",
"verify_interface",
"(",
"ec",
".",
"EllipticCurve",
",",
"self",
".",
"algorithm",
".",
"signing_algorithm_info",
")",
"return",
"ec",
".",
"EllipticCurve",
"except",
"InterfaceNotImplemented",
":",... | Ensures that the algorithm signature type is a known type and sets a reference value. | [
"Ensures",
"that",
"the",
"algorithm",
"signature",
"type",
"is",
"a",
"known",
"type",
"and",
"sets",
"a",
"reference",
"value",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/crypto/authentication.py#L48-L54 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/crypto/authentication.py | Signer.from_key_bytes | def from_key_bytes(cls, algorithm, key_bytes):
"""Builds a `Signer` from an algorithm suite and a raw signing key.
:param algorithm: Algorithm on which to base signer
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes key_bytes: Raw signing key
:rtype: aws_en... | python | def from_key_bytes(cls, algorithm, key_bytes):
"""Builds a `Signer` from an algorithm suite and a raw signing key.
:param algorithm: Algorithm on which to base signer
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes key_bytes: Raw signing key
:rtype: aws_en... | [
"def",
"from_key_bytes",
"(",
"cls",
",",
"algorithm",
",",
"key_bytes",
")",
":",
"key",
"=",
"serialization",
".",
"load_der_private_key",
"(",
"data",
"=",
"key_bytes",
",",
"password",
"=",
"None",
",",
"backend",
"=",
"default_backend",
"(",
")",
")",
... | Builds a `Signer` from an algorithm suite and a raw signing key.
:param algorithm: Algorithm on which to base signer
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes key_bytes: Raw signing key
:rtype: aws_encryption_sdk.internal.crypto.Signer | [
"Builds",
"a",
"Signer",
"from",
"an",
"algorithm",
"suite",
"and",
"a",
"raw",
"signing",
"key",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/crypto/authentication.py#L74-L83 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/crypto/authentication.py | Signer.key_bytes | def key_bytes(self):
"""Returns the raw signing key.
:rtype: bytes
"""
return self.key.private_bytes(
encoding=serialization.Encoding.DER,
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.NoEncryption(),
) | python | def key_bytes(self):
"""Returns the raw signing key.
:rtype: bytes
"""
return self.key.private_bytes(
encoding=serialization.Encoding.DER,
format=serialization.PrivateFormat.PKCS8,
encryption_algorithm=serialization.NoEncryption(),
) | [
"def",
"key_bytes",
"(",
"self",
")",
":",
"return",
"self",
".",
"key",
".",
"private_bytes",
"(",
"encoding",
"=",
"serialization",
".",
"Encoding",
".",
"DER",
",",
"format",
"=",
"serialization",
".",
"PrivateFormat",
".",
"PKCS8",
",",
"encryption_algor... | Returns the raw signing key.
:rtype: bytes | [
"Returns",
"the",
"raw",
"signing",
"key",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/crypto/authentication.py#L85-L94 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/crypto/authentication.py | Signer.finalize | def finalize(self):
"""Finalizes the signer and returns the signature.
:returns: Calculated signer signature
:rtype: bytes
"""
prehashed_digest = self._hasher.finalize()
return _ecc_static_length_signature(key=self.key, algorithm=self.algorithm, digest=prehashed_digest) | python | def finalize(self):
"""Finalizes the signer and returns the signature.
:returns: Calculated signer signature
:rtype: bytes
"""
prehashed_digest = self._hasher.finalize()
return _ecc_static_length_signature(key=self.key, algorithm=self.algorithm, digest=prehashed_digest) | [
"def",
"finalize",
"(",
"self",
")",
":",
"prehashed_digest",
"=",
"self",
".",
"_hasher",
".",
"finalize",
"(",
")",
"return",
"_ecc_static_length_signature",
"(",
"key",
"=",
"self",
".",
"key",
",",
"algorithm",
"=",
"self",
".",
"algorithm",
",",
"dige... | Finalizes the signer and returns the signature.
:returns: Calculated signer signature
:rtype: bytes | [
"Finalizes",
"the",
"signer",
"and",
"returns",
"the",
"signature",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/crypto/authentication.py#L114-L121 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/crypto/authentication.py | Verifier.from_encoded_point | def from_encoded_point(cls, algorithm, encoded_point):
"""Creates a Verifier object based on the supplied algorithm and encoded compressed ECC curve point.
:param algorithm: Algorithm on which to base verifier
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes encode... | python | def from_encoded_point(cls, algorithm, encoded_point):
"""Creates a Verifier object based on the supplied algorithm and encoded compressed ECC curve point.
:param algorithm: Algorithm on which to base verifier
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes encode... | [
"def",
"from_encoded_point",
"(",
"cls",
",",
"algorithm",
",",
"encoded_point",
")",
":",
"return",
"cls",
"(",
"algorithm",
"=",
"algorithm",
",",
"key",
"=",
"_ecc_public_numbers_from_compressed_point",
"(",
"curve",
"=",
"algorithm",
".",
"signing_algorithm_info... | Creates a Verifier object based on the supplied algorithm and encoded compressed ECC curve point.
:param algorithm: Algorithm on which to base verifier
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes encoded_point: ECC public point compressed and encoded with _ecc_encode_... | [
"Creates",
"a",
"Verifier",
"object",
"based",
"on",
"the",
"supplied",
"algorithm",
"and",
"encoded",
"compressed",
"ECC",
"curve",
"point",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/crypto/authentication.py#L137-L151 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/crypto/authentication.py | Verifier.from_key_bytes | def from_key_bytes(cls, algorithm, key_bytes):
"""Creates a `Verifier` object based on the supplied algorithm and raw verification key.
:param algorithm: Algorithm on which to base verifier
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes encoded_point: Raw verific... | python | def from_key_bytes(cls, algorithm, key_bytes):
"""Creates a `Verifier` object based on the supplied algorithm and raw verification key.
:param algorithm: Algorithm on which to base verifier
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes encoded_point: Raw verific... | [
"def",
"from_key_bytes",
"(",
"cls",
",",
"algorithm",
",",
"key_bytes",
")",
":",
"return",
"cls",
"(",
"algorithm",
"=",
"algorithm",
",",
"key",
"=",
"serialization",
".",
"load_der_public_key",
"(",
"data",
"=",
"key_bytes",
",",
"backend",
"=",
"default... | Creates a `Verifier` object based on the supplied algorithm and raw verification key.
:param algorithm: Algorithm on which to base verifier
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes encoded_point: Raw verification key
:returns: Instance of Verifier generated... | [
"Creates",
"a",
"Verifier",
"object",
"based",
"on",
"the",
"supplied",
"algorithm",
"and",
"raw",
"verification",
"key",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/crypto/authentication.py#L154-L165 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/crypto/authentication.py | Verifier.key_bytes | def key_bytes(self):
"""Returns the raw verification key.
:rtype: bytes
"""
return self.key.public_bytes(
encoding=serialization.Encoding.DER, format=serialization.PublicFormat.SubjectPublicKeyInfo
) | python | def key_bytes(self):
"""Returns the raw verification key.
:rtype: bytes
"""
return self.key.public_bytes(
encoding=serialization.Encoding.DER, format=serialization.PublicFormat.SubjectPublicKeyInfo
) | [
"def",
"key_bytes",
"(",
"self",
")",
":",
"return",
"self",
".",
"key",
".",
"public_bytes",
"(",
"encoding",
"=",
"serialization",
".",
"Encoding",
".",
"DER",
",",
"format",
"=",
"serialization",
".",
"PublicFormat",
".",
"SubjectPublicKeyInfo",
")"
] | Returns the raw verification key.
:rtype: bytes | [
"Returns",
"the",
"raw",
"verification",
"key",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/crypto/authentication.py#L167-L174 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/crypto/authentication.py | Verifier.verify | def verify(self, signature):
"""Verifies the signature against the current cryptographic verifier state.
:param bytes signature: The signature to verify
"""
prehashed_digest = self._hasher.finalize()
self.key.verify(
signature=signature,
data=prehashed_di... | python | def verify(self, signature):
"""Verifies the signature against the current cryptographic verifier state.
:param bytes signature: The signature to verify
"""
prehashed_digest = self._hasher.finalize()
self.key.verify(
signature=signature,
data=prehashed_di... | [
"def",
"verify",
"(",
"self",
",",
"signature",
")",
":",
"prehashed_digest",
"=",
"self",
".",
"_hasher",
".",
"finalize",
"(",
")",
"self",
".",
"key",
".",
"verify",
"(",
"signature",
"=",
"signature",
",",
"data",
"=",
"prehashed_digest",
",",
"signa... | Verifies the signature against the current cryptographic verifier state.
:param bytes signature: The signature to verify | [
"Verifies",
"the",
"signature",
"against",
"the",
"current",
"cryptographic",
"verifier",
"state",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/crypto/authentication.py#L183-L193 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/crypto/wrapping_keys.py | WrappingKey.encrypt | def encrypt(self, plaintext_data_key, encryption_context):
"""Encrypts a data key using a direct wrapping key.
:param bytes plaintext_data_key: Data key to encrypt
:param dict encryption_context: Encryption context to use in encryption
:returns: Deserialized object containing encrypted ... | python | def encrypt(self, plaintext_data_key, encryption_context):
"""Encrypts a data key using a direct wrapping key.
:param bytes plaintext_data_key: Data key to encrypt
:param dict encryption_context: Encryption context to use in encryption
:returns: Deserialized object containing encrypted ... | [
"def",
"encrypt",
"(",
"self",
",",
"plaintext_data_key",
",",
"encryption_context",
")",
":",
"if",
"self",
".",
"wrapping_algorithm",
".",
"encryption_type",
"is",
"EncryptionType",
".",
"ASYMMETRIC",
":",
"if",
"self",
".",
"wrapping_key_type",
"is",
"Encryptio... | Encrypts a data key using a direct wrapping key.
:param bytes plaintext_data_key: Data key to encrypt
:param dict encryption_context: Encryption context to use in encryption
:returns: Deserialized object containing encrypted key
:rtype: aws_encryption_sdk.internal.structures.EncryptedDa... | [
"Encrypts",
"a",
"data",
"key",
"using",
"a",
"direct",
"wrapping",
"key",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/crypto/wrapping_keys.py#L61-L87 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/crypto/wrapping_keys.py | WrappingKey.decrypt | def decrypt(self, encrypted_wrapped_data_key, encryption_context):
"""Decrypts a wrapped, encrypted, data key.
:param encrypted_wrapped_data_key: Encrypted, wrapped, data key
:type encrypted_wrapped_data_key: aws_encryption_sdk.internal.structures.EncryptedData
:param dict encryption_co... | python | def decrypt(self, encrypted_wrapped_data_key, encryption_context):
"""Decrypts a wrapped, encrypted, data key.
:param encrypted_wrapped_data_key: Encrypted, wrapped, data key
:type encrypted_wrapped_data_key: aws_encryption_sdk.internal.structures.EncryptedData
:param dict encryption_co... | [
"def",
"decrypt",
"(",
"self",
",",
"encrypted_wrapped_data_key",
",",
"encryption_context",
")",
":",
"if",
"self",
".",
"wrapping_key_type",
"is",
"EncryptionKeyType",
".",
"PUBLIC",
":",
"raise",
"IncorrectMasterKeyError",
"(",
"\"Public key cannot decrypt\"",
")",
... | Decrypts a wrapped, encrypted, data key.
:param encrypted_wrapped_data_key: Encrypted, wrapped, data key
:type encrypted_wrapped_data_key: aws_encryption_sdk.internal.structures.EncryptedData
:param dict encryption_context: Encryption context to use in decryption
:returns: Plaintext of ... | [
"Decrypts",
"a",
"wrapped",
"encrypted",
"data",
"key",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/crypto/wrapping_keys.py#L89-L110 | train |
aws/aws-encryption-sdk-python | decrypt_oracle/src/aws_encryption_sdk_decrypt_oracle/key_providers/counting.py | CountingMasterKey._generate_data_key | def _generate_data_key(self, algorithm: AlgorithmSuite, encryption_context: Dict[Text, Text]) -> DataKey:
"""Perform the provider-specific data key generation task.
:param algorithm: Algorithm on which to base data key
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param dic... | python | def _generate_data_key(self, algorithm: AlgorithmSuite, encryption_context: Dict[Text, Text]) -> DataKey:
"""Perform the provider-specific data key generation task.
:param algorithm: Algorithm on which to base data key
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param dic... | [
"def",
"_generate_data_key",
"(",
"self",
",",
"algorithm",
":",
"AlgorithmSuite",
",",
"encryption_context",
":",
"Dict",
"[",
"Text",
",",
"Text",
"]",
")",
"->",
"DataKey",
":",
"data_key",
"=",
"b\"\"",
".",
"join",
"(",
"[",
"chr",
"(",
"i",
")",
... | Perform the provider-specific data key generation task.
:param algorithm: Algorithm on which to base data key
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param dict encryption_context: Encryption context to use in encryption
:returns: Generated data key
:rtype: aw... | [
"Perform",
"the",
"provider",
"-",
"specific",
"data",
"key",
"generation",
"task",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/decrypt_oracle/src/aws_encryption_sdk_decrypt_oracle/key_providers/counting.py#L53-L63 | train |
aws/aws-encryption-sdk-python | decrypt_oracle/src/aws_encryption_sdk_decrypt_oracle/key_providers/counting.py | CountingMasterKey._encrypt_data_key | def _encrypt_data_key(
self, data_key: DataKey, algorithm: AlgorithmSuite, encryption_context: Dict[Text, Text]
) -> NoReturn:
"""Encrypt a data key and return the ciphertext.
:param data_key: Unencrypted data key
:type data_key: :class:`aws_encryption_sdk.structures.RawDataKey`
... | python | def _encrypt_data_key(
self, data_key: DataKey, algorithm: AlgorithmSuite, encryption_context: Dict[Text, Text]
) -> NoReturn:
"""Encrypt a data key and return the ciphertext.
:param data_key: Unencrypted data key
:type data_key: :class:`aws_encryption_sdk.structures.RawDataKey`
... | [
"def",
"_encrypt_data_key",
"(",
"self",
",",
"data_key",
":",
"DataKey",
",",
"algorithm",
":",
"AlgorithmSuite",
",",
"encryption_context",
":",
"Dict",
"[",
"Text",
",",
"Text",
"]",
")",
"->",
"NoReturn",
":",
"raise",
"NotImplementedError",
"(",
"\"Counti... | Encrypt a data key and return the ciphertext.
:param data_key: Unencrypted data key
:type data_key: :class:`aws_encryption_sdk.structures.RawDataKey`
or :class:`aws_encryption_sdk.structures.DataKey`
:param algorithm: Algorithm object which directs how this Master Key will encrypt t... | [
"Encrypt",
"a",
"data",
"key",
"and",
"return",
"the",
"ciphertext",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/decrypt_oracle/src/aws_encryption_sdk_decrypt_oracle/key_providers/counting.py#L65-L78 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/deserialize.py | validate_header | def validate_header(header, header_auth, raw_header, data_key):
"""Validates the header using the header authentication data.
:param header: Deserialized header
:type header: aws_encryption_sdk.structures.MessageHeader
:param header_auth: Deserialized header auth
:type header_auth: aws_encryption_s... | python | def validate_header(header, header_auth, raw_header, data_key):
"""Validates the header using the header authentication data.
:param header: Deserialized header
:type header: aws_encryption_sdk.structures.MessageHeader
:param header_auth: Deserialized header auth
:type header_auth: aws_encryption_s... | [
"def",
"validate_header",
"(",
"header",
",",
"header_auth",
",",
"raw_header",
",",
"data_key",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Starting header validation\"",
")",
"try",
":",
"decrypt",
"(",
"algorithm",
"=",
"header",
".",
"algorithm",
",",
"key"... | Validates the header using the header authentication data.
:param header: Deserialized header
:type header: aws_encryption_sdk.structures.MessageHeader
:param header_auth: Deserialized header auth
:type header_auth: aws_encryption_sdk.internal.structures.MessageHeaderAuthentication
:type stream: io... | [
"Validates",
"the",
"header",
"using",
"the",
"header",
"authentication",
"data",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/deserialize.py#L52-L73 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/deserialize.py | _deserialize_encrypted_data_keys | def _deserialize_encrypted_data_keys(stream):
# type: (IO) -> Set[EncryptedDataKey]
"""Deserialize some encrypted data keys from a stream.
:param stream: Stream from which to read encrypted data keys
:return: Loaded encrypted data keys
:rtype: set of :class:`EncryptedDataKey`
"""
(encrypted... | python | def _deserialize_encrypted_data_keys(stream):
# type: (IO) -> Set[EncryptedDataKey]
"""Deserialize some encrypted data keys from a stream.
:param stream: Stream from which to read encrypted data keys
:return: Loaded encrypted data keys
:rtype: set of :class:`EncryptedDataKey`
"""
(encrypted... | [
"def",
"_deserialize_encrypted_data_keys",
"(",
"stream",
")",
":",
"# type: (IO) -> Set[EncryptedDataKey]",
"(",
"encrypted_data_key_count",
",",
")",
"=",
"unpack_values",
"(",
"\">H\"",
",",
"stream",
")",
"encrypted_data_keys",
"=",
"set",
"(",
"[",
"]",
")",
"f... | Deserialize some encrypted data keys from a stream.
:param stream: Stream from which to read encrypted data keys
:return: Loaded encrypted data keys
:rtype: set of :class:`EncryptedDataKey` | [
"Deserialize",
"some",
"encrypted",
"data",
"keys",
"from",
"a",
"stream",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/deserialize.py#L127-L152 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/deserialize.py | _verified_iv_length | def _verified_iv_length(iv_length, algorithm_suite):
# type: (int, AlgorithmSuite) -> int
"""Verify an IV length for an algorithm suite.
:param int iv_length: IV length to verify
:param AlgorithmSuite algorithm_suite: Algorithm suite to verify against
:return: IV length
:rtype: int
:raises ... | python | def _verified_iv_length(iv_length, algorithm_suite):
# type: (int, AlgorithmSuite) -> int
"""Verify an IV length for an algorithm suite.
:param int iv_length: IV length to verify
:param AlgorithmSuite algorithm_suite: Algorithm suite to verify against
:return: IV length
:rtype: int
:raises ... | [
"def",
"_verified_iv_length",
"(",
"iv_length",
",",
"algorithm_suite",
")",
":",
"# type: (int, AlgorithmSuite) -> int",
"if",
"iv_length",
"!=",
"algorithm_suite",
".",
"iv_len",
":",
"raise",
"SerializationError",
"(",
"\"Specified IV length ({length}) does not match algorit... | Verify an IV length for an algorithm suite.
:param int iv_length: IV length to verify
:param AlgorithmSuite algorithm_suite: Algorithm suite to verify against
:return: IV length
:rtype: int
:raises SerializationError: if IV length does not match algorithm suite | [
"Verify",
"an",
"IV",
"length",
"for",
"an",
"algorithm",
"suite",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/deserialize.py#L185-L202 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/deserialize.py | _verified_frame_length | def _verified_frame_length(frame_length, content_type):
# type: (int, ContentType) -> int
"""Verify a frame length value for a message content type.
:param int frame_length: Frame length to verify
:param ContentType content_type: Message content type to verify against
:return: frame length
:rty... | python | def _verified_frame_length(frame_length, content_type):
# type: (int, ContentType) -> int
"""Verify a frame length value for a message content type.
:param int frame_length: Frame length to verify
:param ContentType content_type: Message content type to verify against
:return: frame length
:rty... | [
"def",
"_verified_frame_length",
"(",
"frame_length",
",",
"content_type",
")",
":",
"# type: (int, ContentType) -> int",
"if",
"content_type",
"==",
"ContentType",
".",
"FRAMED_DATA",
"and",
"frame_length",
">",
"MAX_FRAME_SIZE",
":",
"raise",
"SerializationError",
"(",
... | Verify a frame length value for a message content type.
:param int frame_length: Frame length to verify
:param ContentType content_type: Message content type to verify against
:return: frame length
:rtype: int
:raises SerializationError: if frame length is too large
:raises SerializationError: ... | [
"Verify",
"a",
"frame",
"length",
"value",
"for",
"a",
"message",
"content",
"type",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/deserialize.py#L205-L226 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/deserialize.py | deserialize_header | def deserialize_header(stream):
# type: (IO) -> MessageHeader
"""Deserializes the header from a source stream
:param stream: Source data stream
:type stream: io.BytesIO
:returns: Deserialized MessageHeader object
:rtype: :class:`aws_encryption_sdk.structures.MessageHeader` and bytes
:raises... | python | def deserialize_header(stream):
# type: (IO) -> MessageHeader
"""Deserializes the header from a source stream
:param stream: Source data stream
:type stream: io.BytesIO
:returns: Deserialized MessageHeader object
:rtype: :class:`aws_encryption_sdk.structures.MessageHeader` and bytes
:raises... | [
"def",
"deserialize_header",
"(",
"stream",
")",
":",
"# type: (IO) -> MessageHeader",
"_LOGGER",
".",
"debug",
"(",
"\"Starting header deserialization\"",
")",
"tee",
"=",
"io",
".",
"BytesIO",
"(",
")",
"tee_stream",
"=",
"TeeStream",
"(",
"stream",
",",
"tee",
... | Deserializes the header from a source stream
:param stream: Source data stream
:type stream: io.BytesIO
:returns: Deserialized MessageHeader object
:rtype: :class:`aws_encryption_sdk.structures.MessageHeader` and bytes
:raises NotSupportedError: if unsupported data types are found
:raises Unkno... | [
"Deserializes",
"the",
"header",
"from",
"a",
"source",
"stream"
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/deserialize.py#L229-L270 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/deserialize.py | deserialize_header_auth | def deserialize_header_auth(stream, algorithm, verifier=None):
"""Deserializes a MessageHeaderAuthentication object from a source stream.
:param stream: Source data stream
:type stream: io.BytesIO
:param algorithm: The AlgorithmSuite object type contained in the header
:type algorith: aws_encryptio... | python | def deserialize_header_auth(stream, algorithm, verifier=None):
"""Deserializes a MessageHeaderAuthentication object from a source stream.
:param stream: Source data stream
:type stream: io.BytesIO
:param algorithm: The AlgorithmSuite object type contained in the header
:type algorith: aws_encryptio... | [
"def",
"deserialize_header_auth",
"(",
"stream",
",",
"algorithm",
",",
"verifier",
"=",
"None",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Starting header auth deserialization\"",
")",
"format_string",
"=",
"\">{iv_len}s{tag_len}s\"",
".",
"format",
"(",
"iv_len",
... | Deserializes a MessageHeaderAuthentication object from a source stream.
:param stream: Source data stream
:type stream: io.BytesIO
:param algorithm: The AlgorithmSuite object type contained in the header
:type algorith: aws_encryption_sdk.identifiers.AlgorithmSuite
:param verifier: Signature verifi... | [
"Deserializes",
"a",
"MessageHeaderAuthentication",
"object",
"from",
"a",
"source",
"stream",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/deserialize.py#L273-L287 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/deserialize.py | deserialize_non_framed_values | def deserialize_non_framed_values(stream, header, verifier=None):
"""Deserializes the IV and body length from a non-framed stream.
:param stream: Source data stream
:type stream: io.BytesIO
:param header: Deserialized header
:type header: aws_encryption_sdk.structures.MessageHeader
:param verif... | python | def deserialize_non_framed_values(stream, header, verifier=None):
"""Deserializes the IV and body length from a non-framed stream.
:param stream: Source data stream
:type stream: io.BytesIO
:param header: Deserialized header
:type header: aws_encryption_sdk.structures.MessageHeader
:param verif... | [
"def",
"deserialize_non_framed_values",
"(",
"stream",
",",
"header",
",",
"verifier",
"=",
"None",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Starting non-framed body iv/tag deserialization\"",
")",
"(",
"data_iv",
",",
"data_length",
")",
"=",
"unpack_values",
"("... | Deserializes the IV and body length from a non-framed stream.
:param stream: Source data stream
:type stream: io.BytesIO
:param header: Deserialized header
:type header: aws_encryption_sdk.structures.MessageHeader
:param verifier: Signature verifier object (optional)
:type verifier: aws_encrypt... | [
"Deserializes",
"the",
"IV",
"and",
"body",
"length",
"from",
"a",
"non",
"-",
"framed",
"stream",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/deserialize.py#L290-L304 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/deserialize.py | deserialize_tag | def deserialize_tag(stream, header, verifier=None):
"""Deserialize the Tag value from a non-framed stream.
:param stream: Source data stream
:type stream: io.BytesIO
:param header: Deserialized header
:type header: aws_encryption_sdk.structures.MessageHeader
:param verifier: Signature verifier ... | python | def deserialize_tag(stream, header, verifier=None):
"""Deserialize the Tag value from a non-framed stream.
:param stream: Source data stream
:type stream: io.BytesIO
:param header: Deserialized header
:type header: aws_encryption_sdk.structures.MessageHeader
:param verifier: Signature verifier ... | [
"def",
"deserialize_tag",
"(",
"stream",
",",
"header",
",",
"verifier",
"=",
"None",
")",
":",
"(",
"data_tag",
",",
")",
"=",
"unpack_values",
"(",
"format_string",
"=",
"\">{auth_len}s\"",
".",
"format",
"(",
"auth_len",
"=",
"header",
".",
"algorithm",
... | Deserialize the Tag value from a non-framed stream.
:param stream: Source data stream
:type stream: io.BytesIO
:param header: Deserialized header
:type header: aws_encryption_sdk.structures.MessageHeader
:param verifier: Signature verifier object (optional)
:type verifier: aws_encryption_sdk.in... | [
"Deserialize",
"the",
"Tag",
"value",
"from",
"a",
"non",
"-",
"framed",
"stream",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/deserialize.py#L307-L322 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/deserialize.py | deserialize_frame | def deserialize_frame(stream, header, verifier=None):
"""Deserializes a frame from a body.
:param stream: Source data stream
:type stream: io.BytesIO
:param header: Deserialized header
:type header: aws_encryption_sdk.structures.MessageHeader
:param verifier: Signature verifier object (optional... | python | def deserialize_frame(stream, header, verifier=None):
"""Deserializes a frame from a body.
:param stream: Source data stream
:type stream: io.BytesIO
:param header: Deserialized header
:type header: aws_encryption_sdk.structures.MessageHeader
:param verifier: Signature verifier object (optional... | [
"def",
"deserialize_frame",
"(",
"stream",
",",
"header",
",",
"verifier",
"=",
"None",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Starting frame deserialization\"",
")",
"frame_data",
"=",
"{",
"}",
"final_frame",
"=",
"False",
"(",
"sequence_number",
",",
")... | Deserializes a frame from a body.
:param stream: Source data stream
:type stream: io.BytesIO
:param header: Deserialized header
:type header: aws_encryption_sdk.structures.MessageHeader
:param verifier: Signature verifier object (optional)
:type verifier: aws_encryption_sdk.internal.crypto.Veri... | [
"Deserializes",
"a",
"frame",
"from",
"a",
"body",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/deserialize.py#L325-L368 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/deserialize.py | deserialize_footer | def deserialize_footer(stream, verifier=None):
"""Deserializes a footer.
:param stream: Source data stream
:type stream: io.BytesIO
:param verifier: Signature verifier object (optional)
:type verifier: aws_encryption_sdk.internal.crypto.Verifier
:returns: Deserialized footer
:rtype: aws_enc... | python | def deserialize_footer(stream, verifier=None):
"""Deserializes a footer.
:param stream: Source data stream
:type stream: io.BytesIO
:param verifier: Signature verifier object (optional)
:type verifier: aws_encryption_sdk.internal.crypto.Verifier
:returns: Deserialized footer
:rtype: aws_enc... | [
"def",
"deserialize_footer",
"(",
"stream",
",",
"verifier",
"=",
"None",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"Starting footer deserialization\"",
")",
"signature",
"=",
"b\"\"",
"if",
"verifier",
"is",
"None",
":",
"return",
"MessageFooter",
"(",
"signatu... | Deserializes a footer.
:param stream: Source data stream
:type stream: io.BytesIO
:param verifier: Signature verifier object (optional)
:type verifier: aws_encryption_sdk.internal.crypto.Verifier
:returns: Deserialized footer
:rtype: aws_encryption_sdk.internal.structures.MessageFooter
:rai... | [
"Deserializes",
"a",
"footer",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/deserialize.py#L371-L393 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/formatting/deserialize.py | deserialize_wrapped_key | def deserialize_wrapped_key(wrapping_algorithm, wrapping_key_id, wrapped_encrypted_key):
"""Extracts and deserializes EncryptedData from a Wrapped EncryptedDataKey.
:param wrapping_algorithm: Wrapping Algorithm with which to wrap plaintext_data_key
:type wrapping_algorithm: aws_encryption_sdk.identifiers.W... | python | def deserialize_wrapped_key(wrapping_algorithm, wrapping_key_id, wrapped_encrypted_key):
"""Extracts and deserializes EncryptedData from a Wrapped EncryptedDataKey.
:param wrapping_algorithm: Wrapping Algorithm with which to wrap plaintext_data_key
:type wrapping_algorithm: aws_encryption_sdk.identifiers.W... | [
"def",
"deserialize_wrapped_key",
"(",
"wrapping_algorithm",
",",
"wrapping_key_id",
",",
"wrapped_encrypted_key",
")",
":",
"if",
"wrapping_key_id",
"==",
"wrapped_encrypted_key",
".",
"key_provider",
".",
"key_info",
":",
"encrypted_wrapped_key",
"=",
"EncryptedData",
"... | Extracts and deserializes EncryptedData from a Wrapped EncryptedDataKey.
:param wrapping_algorithm: Wrapping Algorithm with which to wrap plaintext_data_key
:type wrapping_algorithm: aws_encryption_sdk.identifiers.WrappingAlgorithm
:param bytes wrapping_key_id: Key ID of wrapping MasterKey
:param wrapp... | [
"Extracts",
"and",
"deserializes",
"EncryptedData",
"from",
"a",
"Wrapped",
"EncryptedDataKey",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/formatting/deserialize.py#L417-L451 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/utils/__init__.py | validate_frame_length | def validate_frame_length(frame_length, algorithm):
"""Validates that frame length is within the defined limits and is compatible with the selected algorithm.
:param int frame_length: Frame size in bytes
:param algorithm: Algorithm to use for encryption
:type algorithm: aws_encryption_sdk.identifiers.A... | python | def validate_frame_length(frame_length, algorithm):
"""Validates that frame length is within the defined limits and is compatible with the selected algorithm.
:param int frame_length: Frame size in bytes
:param algorithm: Algorithm to use for encryption
:type algorithm: aws_encryption_sdk.identifiers.A... | [
"def",
"validate_frame_length",
"(",
"frame_length",
",",
"algorithm",
")",
":",
"if",
"frame_length",
"<",
"0",
"or",
"frame_length",
"%",
"algorithm",
".",
"encryption_algorithm",
".",
"block_size",
"!=",
"0",
":",
"raise",
"SerializationError",
"(",
"\"Frame si... | Validates that frame length is within the defined limits and is compatible with the selected algorithm.
:param int frame_length: Frame size in bytes
:param algorithm: Algorithm to use for encryption
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:raises SerializationError: if frame size is n... | [
"Validates",
"that",
"frame",
"length",
"is",
"within",
"the",
"defined",
"limits",
"and",
"is",
"compatible",
"with",
"the",
"selected",
"algorithm",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/utils/__init__.py#L44-L64 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/utils/__init__.py | get_aad_content_string | def get_aad_content_string(content_type, is_final_frame):
"""Prepares the appropriate Body AAD Value for a message body.
:param content_type: Defines the type of content for which to prepare AAD String
:type content_type: aws_encryption_sdk.identifiers.ContentType
:param bool is_final_frame: Boolean st... | python | def get_aad_content_string(content_type, is_final_frame):
"""Prepares the appropriate Body AAD Value for a message body.
:param content_type: Defines the type of content for which to prepare AAD String
:type content_type: aws_encryption_sdk.identifiers.ContentType
:param bool is_final_frame: Boolean st... | [
"def",
"get_aad_content_string",
"(",
"content_type",
",",
"is_final_frame",
")",
":",
"if",
"content_type",
"==",
"ContentType",
".",
"NO_FRAMING",
":",
"aad_content_string",
"=",
"ContentAADString",
".",
"NON_FRAMED_STRING_ID",
"elif",
"content_type",
"==",
"ContentTy... | Prepares the appropriate Body AAD Value for a message body.
:param content_type: Defines the type of content for which to prepare AAD String
:type content_type: aws_encryption_sdk.identifiers.ContentType
:param bool is_final_frame: Boolean stating whether this is the final frame in a body
:returns: App... | [
"Prepares",
"the",
"appropriate",
"Body",
"AAD",
"Value",
"for",
"a",
"message",
"body",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/utils/__init__.py#L76-L95 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/utils/__init__.py | prepare_data_keys | def prepare_data_keys(primary_master_key, master_keys, algorithm, encryption_context):
"""Prepares a DataKey to be used for encrypting message and list
of EncryptedDataKey objects to be serialized into header.
:param primary_master_key: Master key with which to generate the encryption data key
:type pr... | python | def prepare_data_keys(primary_master_key, master_keys, algorithm, encryption_context):
"""Prepares a DataKey to be used for encrypting message and list
of EncryptedDataKey objects to be serialized into header.
:param primary_master_key: Master key with which to generate the encryption data key
:type pr... | [
"def",
"prepare_data_keys",
"(",
"primary_master_key",
",",
"master_keys",
",",
"algorithm",
",",
"encryption_context",
")",
":",
"encrypted_data_keys",
"=",
"set",
"(",
")",
"encrypted_data_encryption_key",
"=",
"None",
"data_encryption_key",
"=",
"primary_master_key",
... | Prepares a DataKey to be used for encrypting message and list
of EncryptedDataKey objects to be serialized into header.
:param primary_master_key: Master key with which to generate the encryption data key
:type primary_master_key: aws_encryption_sdk.key_providers.base.MasterKey
:param master_keys: All ... | [
"Prepares",
"a",
"DataKey",
"to",
"be",
"used",
"for",
"encrypting",
"message",
"and",
"list",
"of",
"EncryptedDataKey",
"objects",
"to",
"be",
"serialized",
"into",
"header",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/utils/__init__.py#L98-L129 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/utils/__init__.py | prep_stream_data | def prep_stream_data(data):
"""Take an input and prepare it for use as a stream.
:param data: Input data
:returns: Prepared stream
:rtype: InsistentReaderBytesIO
"""
if isinstance(data, (six.string_types, six.binary_type)):
stream = io.BytesIO(to_bytes(data))
else:
stream = ... | python | def prep_stream_data(data):
"""Take an input and prepare it for use as a stream.
:param data: Input data
:returns: Prepared stream
:rtype: InsistentReaderBytesIO
"""
if isinstance(data, (six.string_types, six.binary_type)):
stream = io.BytesIO(to_bytes(data))
else:
stream = ... | [
"def",
"prep_stream_data",
"(",
"data",
")",
":",
"if",
"isinstance",
"(",
"data",
",",
"(",
"six",
".",
"string_types",
",",
"six",
".",
"binary_type",
")",
")",
":",
"stream",
"=",
"io",
".",
"BytesIO",
"(",
"to_bytes",
"(",
"data",
")",
")",
"else... | Take an input and prepare it for use as a stream.
:param data: Input data
:returns: Prepared stream
:rtype: InsistentReaderBytesIO | [
"Take",
"an",
"input",
"and",
"prepare",
"it",
"for",
"use",
"as",
"a",
"stream",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/utils/__init__.py#L132-L144 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/utils/__init__.py | source_data_key_length_check | def source_data_key_length_check(source_data_key, algorithm):
"""Validates that the supplied source_data_key's data_key is the
correct length for the supplied algorithm's kdf_input_len value.
:param source_data_key: Source data key object received from MasterKey decrypt or generate data_key methods
:ty... | python | def source_data_key_length_check(source_data_key, algorithm):
"""Validates that the supplied source_data_key's data_key is the
correct length for the supplied algorithm's kdf_input_len value.
:param source_data_key: Source data key object received from MasterKey decrypt or generate data_key methods
:ty... | [
"def",
"source_data_key_length_check",
"(",
"source_data_key",
",",
"algorithm",
")",
":",
"if",
"len",
"(",
"source_data_key",
".",
"data_key",
")",
"!=",
"algorithm",
".",
"kdf_input_len",
":",
"raise",
"InvalidDataKeyError",
"(",
"\"Invalid Source Data Key length {ac... | Validates that the supplied source_data_key's data_key is the
correct length for the supplied algorithm's kdf_input_len value.
:param source_data_key: Source data key object received from MasterKey decrypt or generate data_key methods
:type source_data_key: :class:`aws_encryption_sdk.structures.RawDataKey`... | [
"Validates",
"that",
"the",
"supplied",
"source_data_key",
"s",
"data_key",
"is",
"the",
"correct",
"length",
"for",
"the",
"supplied",
"algorithm",
"s",
"kdf_input_len",
"value",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/utils/__init__.py#L147-L163 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/crypto/encryption.py | encrypt | def encrypt(algorithm, key, plaintext, associated_data, iv):
"""Encrypts a frame body.
:param algorithm: Algorithm used to encrypt this body
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes key: Encryption key
:param bytes plaintext: Body plaintext
:param bytes associated_... | python | def encrypt(algorithm, key, plaintext, associated_data, iv):
"""Encrypts a frame body.
:param algorithm: Algorithm used to encrypt this body
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes key: Encryption key
:param bytes plaintext: Body plaintext
:param bytes associated_... | [
"def",
"encrypt",
"(",
"algorithm",
",",
"key",
",",
"plaintext",
",",
"associated_data",
",",
"iv",
")",
":",
"encryptor",
"=",
"Encryptor",
"(",
"algorithm",
",",
"key",
",",
"associated_data",
",",
"iv",
")",
"ciphertext",
"=",
"encryptor",
".",
"update... | Encrypts a frame body.
:param algorithm: Algorithm used to encrypt this body
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes key: Encryption key
:param bytes plaintext: Body plaintext
:param bytes associated_data: Body AAD Data
:param bytes iv: IV to use when encrypting m... | [
"Encrypts",
"a",
"frame",
"body",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/crypto/encryption.py#L76-L90 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/crypto/encryption.py | decrypt | def decrypt(algorithm, key, encrypted_data, associated_data):
"""Decrypts a frame body.
:param algorithm: Algorithm used to encrypt this body
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes key: Plaintext data key
:param encrypted_data: EncryptedData containing body data
... | python | def decrypt(algorithm, key, encrypted_data, associated_data):
"""Decrypts a frame body.
:param algorithm: Algorithm used to encrypt this body
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes key: Plaintext data key
:param encrypted_data: EncryptedData containing body data
... | [
"def",
"decrypt",
"(",
"algorithm",
",",
"key",
",",
"encrypted_data",
",",
"associated_data",
")",
":",
"decryptor",
"=",
"Decryptor",
"(",
"algorithm",
",",
"key",
",",
"associated_data",
",",
"encrypted_data",
".",
"iv",
",",
"encrypted_data",
".",
"tag",
... | Decrypts a frame body.
:param algorithm: Algorithm used to encrypt this body
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes key: Plaintext data key
:param encrypted_data: EncryptedData containing body data
:type encrypted_data: :class:`aws_encryption_sdk.internal.structures.... | [
"Decrypts",
"a",
"frame",
"body",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/crypto/encryption.py#L135-L151 | train |
aws/aws-encryption-sdk-python | decrypt_oracle/src/aws_encryption_sdk_decrypt_oracle/app.py | _master_key_provider | def _master_key_provider() -> KMSMasterKeyProvider:
"""Build the V0 master key provider."""
master_key_provider = KMSMasterKeyProvider()
master_key_provider.add_master_key_provider(NullMasterKey())
master_key_provider.add_master_key_provider(CountingMasterKey())
return master_key_provider | python | def _master_key_provider() -> KMSMasterKeyProvider:
"""Build the V0 master key provider."""
master_key_provider = KMSMasterKeyProvider()
master_key_provider.add_master_key_provider(NullMasterKey())
master_key_provider.add_master_key_provider(CountingMasterKey())
return master_key_provider | [
"def",
"_master_key_provider",
"(",
")",
"->",
"KMSMasterKeyProvider",
":",
"master_key_provider",
"=",
"KMSMasterKeyProvider",
"(",
")",
"master_key_provider",
".",
"add_master_key_provider",
"(",
"NullMasterKey",
"(",
")",
")",
"master_key_provider",
".",
"add_master_ke... | Build the V0 master key provider. | [
"Build",
"the",
"V0",
"master",
"key",
"provider",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/decrypt_oracle/src/aws_encryption_sdk_decrypt_oracle/app.py#L30-L35 | train |
aws/aws-encryption-sdk-python | decrypt_oracle/src/aws_encryption_sdk_decrypt_oracle/app.py | basic_decrypt | def basic_decrypt() -> Response:
"""Basic decrypt handler for decrypt oracle v0.
**Request**
* **Method**: POST
* **Body**: Raw ciphertext bytes
* **Headers**:
* **Content-Type**: ``application/octet-stream``
* **Accept**: ``application/octet-stream``
**Response**
* 200 resp... | python | def basic_decrypt() -> Response:
"""Basic decrypt handler for decrypt oracle v0.
**Request**
* **Method**: POST
* **Body**: Raw ciphertext bytes
* **Headers**:
* **Content-Type**: ``application/octet-stream``
* **Accept**: ``application/octet-stream``
**Response**
* 200 resp... | [
"def",
"basic_decrypt",
"(",
")",
"->",
"Response",
":",
"APP",
".",
"log",
".",
"debug",
"(",
"\"Request:\"",
")",
"APP",
".",
"log",
".",
"debug",
"(",
"json",
".",
"dumps",
"(",
"APP",
".",
"current_request",
".",
"to_dict",
"(",
")",
")",
")",
... | Basic decrypt handler for decrypt oracle v0.
**Request**
* **Method**: POST
* **Body**: Raw ciphertext bytes
* **Headers**:
* **Content-Type**: ``application/octet-stream``
* **Accept**: ``application/octet-stream``
**Response**
* 200 response code with the raw plaintext bytes a... | [
"Basic",
"decrypt",
"handler",
"for",
"decrypt",
"oracle",
"v0",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/decrypt_oracle/src/aws_encryption_sdk_decrypt_oracle/app.py#L39-L72 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/utils/streams.py | TeeStream.read | def read(self, b=None):
"""Reads data from source, copying it into ``tee`` before returning.
:param int b: number of bytes to read
"""
data = self.__wrapped__.read(b)
self.__tee.write(data)
return data | python | def read(self, b=None):
"""Reads data from source, copying it into ``tee`` before returning.
:param int b: number of bytes to read
"""
data = self.__wrapped__.read(b)
self.__tee.write(data)
return data | [
"def",
"read",
"(",
"self",
",",
"b",
"=",
"None",
")",
":",
"data",
"=",
"self",
".",
"__wrapped__",
".",
"read",
"(",
"b",
")",
"self",
".",
"__tee",
".",
"write",
"(",
"data",
")",
"return",
"data"
] | Reads data from source, copying it into ``tee`` before returning.
:param int b: number of bytes to read | [
"Reads",
"data",
"from",
"source",
"copying",
"it",
"into",
"tee",
"before",
"returning",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/utils/streams.py#L54-L61 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/utils/streams.py | InsistentReaderBytesIO.read | def read(self, b=-1):
"""Keep reading from source stream until either the source stream is done
or the requested number of bytes have been obtained.
:param int b: number of bytes to read
:return: All bytes read from wrapped stream
:rtype: bytes
"""
remaining_byte... | python | def read(self, b=-1):
"""Keep reading from source stream until either the source stream is done
or the requested number of bytes have been obtained.
:param int b: number of bytes to read
:return: All bytes read from wrapped stream
:rtype: bytes
"""
remaining_byte... | [
"def",
"read",
"(",
"self",
",",
"b",
"=",
"-",
"1",
")",
":",
"remaining_bytes",
"=",
"b",
"data",
"=",
"io",
".",
"BytesIO",
"(",
")",
"while",
"True",
":",
"try",
":",
"chunk",
"=",
"to_bytes",
"(",
"self",
".",
"__wrapped__",
".",
"read",
"("... | Keep reading from source stream until either the source stream is done
or the requested number of bytes have been obtained.
:param int b: number of bytes to read
:return: All bytes read from wrapped stream
:rtype: bytes | [
"Keep",
"reading",
"from",
"source",
"stream",
"until",
"either",
"the",
"source",
"stream",
"is",
"done",
"or",
"the",
"requested",
"number",
"of",
"bytes",
"have",
"been",
"obtained",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/utils/streams.py#L73-L99 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/crypto/elliptic_curve.py | _ecc_static_length_signature | def _ecc_static_length_signature(key, algorithm, digest):
"""Calculates an elliptic curve signature with a static length using pre-calculated hash.
:param key: Elliptic curve private key
:type key: cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey
:param algorithm: Master algorithm t... | python | def _ecc_static_length_signature(key, algorithm, digest):
"""Calculates an elliptic curve signature with a static length using pre-calculated hash.
:param key: Elliptic curve private key
:type key: cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey
:param algorithm: Master algorithm t... | [
"def",
"_ecc_static_length_signature",
"(",
"key",
",",
"algorithm",
",",
"digest",
")",
":",
"pre_hashed_algorithm",
"=",
"ec",
".",
"ECDSA",
"(",
"Prehashed",
"(",
"algorithm",
".",
"signing_hash_type",
"(",
")",
")",
")",
"signature",
"=",
"b\"\"",
"while",... | Calculates an elliptic curve signature with a static length using pre-calculated hash.
:param key: Elliptic curve private key
:type key: cryptography.hazmat.primitives.asymmetric.ec.EllipticCurvePrivateKey
:param algorithm: Master algorithm to use
:type algorithm: aws_encryption_sdk.identifiers.Algorit... | [
"Calculates",
"an",
"elliptic",
"curve",
"signature",
"with",
"a",
"static",
"length",
"using",
"pre",
"-",
"calculated",
"hash",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/crypto/elliptic_curve.py#L55-L82 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/crypto/elliptic_curve.py | generate_ecc_signing_key | def generate_ecc_signing_key(algorithm):
"""Returns an ECC signing key.
:param algorithm: Algorithm object which determines what signature to generate
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:returns: Generated signing key
:raises NotSupportedError: if signing algorithm is not sup... | python | def generate_ecc_signing_key(algorithm):
"""Returns an ECC signing key.
:param algorithm: Algorithm object which determines what signature to generate
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:returns: Generated signing key
:raises NotSupportedError: if signing algorithm is not sup... | [
"def",
"generate_ecc_signing_key",
"(",
"algorithm",
")",
":",
"try",
":",
"verify_interface",
"(",
"ec",
".",
"EllipticCurve",
",",
"algorithm",
".",
"signing_algorithm_info",
")",
"return",
"ec",
".",
"generate_private_key",
"(",
"curve",
"=",
"algorithm",
".",
... | Returns an ECC signing key.
:param algorithm: Algorithm object which determines what signature to generate
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:returns: Generated signing key
:raises NotSupportedError: if signing algorithm is not supported on this platform | [
"Returns",
"an",
"ECC",
"signing",
"key",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/crypto/elliptic_curve.py#L177-L189 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/internal/crypto/data_keys.py | derive_data_encryption_key | def derive_data_encryption_key(source_key, algorithm, message_id):
"""Derives the data encryption key using the defined algorithm.
:param bytes source_key: Raw source key
:param algorithm: Algorithm used to encrypt this body
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes mes... | python | def derive_data_encryption_key(source_key, algorithm, message_id):
"""Derives the data encryption key using the defined algorithm.
:param bytes source_key: Raw source key
:param algorithm: Algorithm used to encrypt this body
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes mes... | [
"def",
"derive_data_encryption_key",
"(",
"source_key",
",",
"algorithm",
",",
"message_id",
")",
":",
"key",
"=",
"source_key",
"if",
"algorithm",
".",
"kdf_type",
"is",
"not",
"None",
":",
"key",
"=",
"algorithm",
".",
"kdf_type",
"(",
"algorithm",
"=",
"a... | Derives the data encryption key using the defined algorithm.
:param bytes source_key: Raw source key
:param algorithm: Algorithm used to encrypt this body
:type algorithm: aws_encryption_sdk.identifiers.Algorithm
:param bytes message_id: Message ID
:returns: Derived data encryption key
:rtype: ... | [
"Derives",
"the",
"data",
"encryption",
"key",
"using",
"the",
"defined",
"algorithm",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/internal/crypto/data_keys.py#L22-L41 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/__init__.py | encrypt | def encrypt(**kwargs):
"""Encrypts and serializes provided plaintext.
.. note::
When using this function, the entire ciphertext message is encrypted into memory before returning
any data. If streaming is desired, see :class:`aws_encryption_sdk.stream`.
.. code:: python
>>> import... | python | def encrypt(**kwargs):
"""Encrypts and serializes provided plaintext.
.. note::
When using this function, the entire ciphertext message is encrypted into memory before returning
any data. If streaming is desired, see :class:`aws_encryption_sdk.stream`.
.. code:: python
>>> import... | [
"def",
"encrypt",
"(",
"*",
"*",
"kwargs",
")",
":",
"with",
"StreamEncryptor",
"(",
"*",
"*",
"kwargs",
")",
"as",
"encryptor",
":",
"ciphertext",
"=",
"encryptor",
".",
"read",
"(",
")",
"return",
"ciphertext",
",",
"encryptor",
".",
"header"
] | Encrypts and serializes provided plaintext.
.. note::
When using this function, the entire ciphertext message is encrypted into memory before returning
any data. If streaming is desired, see :class:`aws_encryption_sdk.stream`.
.. code:: python
>>> import aws_encryption_sdk
>>... | [
"Encrypts",
"and",
"serializes",
"provided",
"plaintext",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/__init__.py#L29-L80 | train |
aws/aws-encryption-sdk-python | src/aws_encryption_sdk/__init__.py | decrypt | def decrypt(**kwargs):
"""Deserializes and decrypts provided ciphertext.
.. note::
When using this function, the entire ciphertext message is decrypted into memory before returning
any data. If streaming is desired, see :class:`aws_encryption_sdk.stream`.
.. code:: python
>>> imp... | python | def decrypt(**kwargs):
"""Deserializes and decrypts provided ciphertext.
.. note::
When using this function, the entire ciphertext message is decrypted into memory before returning
any data. If streaming is desired, see :class:`aws_encryption_sdk.stream`.
.. code:: python
>>> imp... | [
"def",
"decrypt",
"(",
"*",
"*",
"kwargs",
")",
":",
"with",
"StreamDecryptor",
"(",
"*",
"*",
"kwargs",
")",
"as",
"decryptor",
":",
"plaintext",
"=",
"decryptor",
".",
"read",
"(",
")",
"return",
"plaintext",
",",
"decryptor",
".",
"header"
] | Deserializes and decrypts provided ciphertext.
.. note::
When using this function, the entire ciphertext message is decrypted into memory before returning
any data. If streaming is desired, see :class:`aws_encryption_sdk.stream`.
.. code:: python
>>> import aws_encryption_sdk
... | [
"Deserializes",
"and",
"decrypts",
"provided",
"ciphertext",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/src/aws_encryption_sdk/__init__.py#L83-L125 | train |
aws/aws-encryption-sdk-python | examples/src/basic_file_encryption_with_multiple_providers.py | cycle_file | def cycle_file(key_arn, source_plaintext_filename, botocore_session=None):
"""Encrypts and then decrypts a file using a KMS master key provider and a custom static master
key provider. Both master key providers are used to encrypt the plaintext file, so either one alone
can decrypt it.
:param str key_a... | python | def cycle_file(key_arn, source_plaintext_filename, botocore_session=None):
"""Encrypts and then decrypts a file using a KMS master key provider and a custom static master
key provider. Both master key providers are used to encrypt the plaintext file, so either one alone
can decrypt it.
:param str key_a... | [
"def",
"cycle_file",
"(",
"key_arn",
",",
"source_plaintext_filename",
",",
"botocore_session",
"=",
"None",
")",
":",
"# \"Cycled\" means encrypted and then decrypted",
"ciphertext_filename",
"=",
"source_plaintext_filename",
"+",
"\".encrypted\"",
"cycled_kms_plaintext_filename... | Encrypts and then decrypts a file using a KMS master key provider and a custom static master
key provider. Both master key providers are used to encrypt the plaintext file, so either one alone
can decrypt it.
:param str key_arn: Amazon Resource Name (ARN) of the KMS Customer Master Key (CMK)
(http://do... | [
"Encrypts",
"and",
"then",
"decrypts",
"a",
"file",
"using",
"a",
"KMS",
"master",
"key",
"provider",
"and",
"a",
"custom",
"static",
"master",
"key",
"provider",
".",
"Both",
"master",
"key",
"providers",
"are",
"used",
"to",
"encrypt",
"the",
"plaintext",
... | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/examples/src/basic_file_encryption_with_multiple_providers.py#L63-L133 | train |
aws/aws-encryption-sdk-python | examples/src/basic_file_encryption_with_multiple_providers.py | StaticRandomMasterKeyProvider._get_raw_key | def _get_raw_key(self, key_id):
"""Retrieves a static, randomly generated, RSA key for the specified key id.
:param str key_id: User-defined ID for the static key
:returns: Wrapping key that contains the specified static key
:rtype: :class:`aws_encryption_sdk.internal.crypto.WrappingKey... | python | def _get_raw_key(self, key_id):
"""Retrieves a static, randomly generated, RSA key for the specified key id.
:param str key_id: User-defined ID for the static key
:returns: Wrapping key that contains the specified static key
:rtype: :class:`aws_encryption_sdk.internal.crypto.WrappingKey... | [
"def",
"_get_raw_key",
"(",
"self",
",",
"key_id",
")",
":",
"try",
":",
"static_key",
"=",
"self",
".",
"_static_keys",
"[",
"key_id",
"]",
"except",
"KeyError",
":",
"private_key",
"=",
"rsa",
".",
"generate_private_key",
"(",
"public_exponent",
"=",
"6553... | Retrieves a static, randomly generated, RSA key for the specified key id.
:param str key_id: User-defined ID for the static key
:returns: Wrapping key that contains the specified static key
:rtype: :class:`aws_encryption_sdk.internal.crypto.WrappingKey` | [
"Retrieves",
"a",
"static",
"randomly",
"generated",
"RSA",
"key",
"for",
"the",
"specified",
"key",
"id",
"."
] | d182155d5fb1ef176d9e7d0647679737d5146495 | https://github.com/aws/aws-encryption-sdk-python/blob/d182155d5fb1ef176d9e7d0647679737d5146495/examples/src/basic_file_encryption_with_multiple_providers.py#L39-L60 | train |
dakrauth/django-swingtime | swingtime/utils.py | month_boundaries | def month_boundaries(dt=None):
'''
Return a 2-tuple containing the datetime instances for the first and last
dates of the current month or using ``dt`` as a reference.
'''
dt = dt or date.today()
wkday, ndays = calendar.monthrange(dt.year, dt.month)
start = datetime(dt.year, dt.month, 1)
... | python | def month_boundaries(dt=None):
'''
Return a 2-tuple containing the datetime instances for the first and last
dates of the current month or using ``dt`` as a reference.
'''
dt = dt or date.today()
wkday, ndays = calendar.monthrange(dt.year, dt.month)
start = datetime(dt.year, dt.month, 1)
... | [
"def",
"month_boundaries",
"(",
"dt",
"=",
"None",
")",
":",
"dt",
"=",
"dt",
"or",
"date",
".",
"today",
"(",
")",
"wkday",
",",
"ndays",
"=",
"calendar",
".",
"monthrange",
"(",
"dt",
".",
"year",
",",
"dt",
".",
"month",
")",
"start",
"=",
"da... | Return a 2-tuple containing the datetime instances for the first and last
dates of the current month or using ``dt`` as a reference. | [
"Return",
"a",
"2",
"-",
"tuple",
"containing",
"the",
"datetime",
"instances",
"for",
"the",
"first",
"and",
"last",
"dates",
"of",
"the",
"current",
"month",
"or",
"using",
"dt",
"as",
"a",
"reference",
"."
] | d1cdd449bd5c6895c3ff182fd890c4d3452943fe | https://github.com/dakrauth/django-swingtime/blob/d1cdd449bd5c6895c3ff182fd890c4d3452943fe/swingtime/utils.py#L27-L36 | train |
dakrauth/django-swingtime | swingtime/utils.py | css_class_cycler | def css_class_cycler():
'''
Return a dictionary keyed by ``EventType`` abbreviations, whose values are an
iterable or cycle of CSS class names.
'''
FMT = 'evt-{0}-{1}'.format
return defaultdict(default_css_class_cycler, (
(e.abbr, itertools.cycle((FMT(e.abbr, 'even'), FMT(e.abbr, 'odd')... | python | def css_class_cycler():
'''
Return a dictionary keyed by ``EventType`` abbreviations, whose values are an
iterable or cycle of CSS class names.
'''
FMT = 'evt-{0}-{1}'.format
return defaultdict(default_css_class_cycler, (
(e.abbr, itertools.cycle((FMT(e.abbr, 'even'), FMT(e.abbr, 'odd')... | [
"def",
"css_class_cycler",
"(",
")",
":",
"FMT",
"=",
"'evt-{0}-{1}'",
".",
"format",
"return",
"defaultdict",
"(",
"default_css_class_cycler",
",",
"(",
"(",
"e",
".",
"abbr",
",",
"itertools",
".",
"cycle",
"(",
"(",
"FMT",
"(",
"e",
".",
"abbr",
",",
... | Return a dictionary keyed by ``EventType`` abbreviations, whose values are an
iterable or cycle of CSS class names. | [
"Return",
"a",
"dictionary",
"keyed",
"by",
"EventType",
"abbreviations",
"whose",
"values",
"are",
"an",
"iterable",
"or",
"cycle",
"of",
"CSS",
"class",
"names",
"."
] | d1cdd449bd5c6895c3ff182fd890c4d3452943fe | https://github.com/dakrauth/django-swingtime/blob/d1cdd449bd5c6895c3ff182fd890c4d3452943fe/swingtime/utils.py#L43-L53 | train |
dakrauth/django-swingtime | swingtime/models.py | create_event | def create_event(
title,
event_type,
description='',
start_time=None,
end_time=None,
note=None,
**rrule_params
):
'''
Convenience function to create an ``Event``, optionally create an
``EventType``, and associated ``Occurrence``s. ``Occurrence`` creation
rules match those for... | python | def create_event(
title,
event_type,
description='',
start_time=None,
end_time=None,
note=None,
**rrule_params
):
'''
Convenience function to create an ``Event``, optionally create an
``EventType``, and associated ``Occurrence``s. ``Occurrence`` creation
rules match those for... | [
"def",
"create_event",
"(",
"title",
",",
"event_type",
",",
"description",
"=",
"''",
",",
"start_time",
"=",
"None",
",",
"end_time",
"=",
"None",
",",
"note",
"=",
"None",
",",
"*",
"*",
"rrule_params",
")",
":",
"if",
"isinstance",
"(",
"event_type",... | Convenience function to create an ``Event``, optionally create an
``EventType``, and associated ``Occurrence``s. ``Occurrence`` creation
rules match those for ``Event.add_occurrences``.
Returns the newly created ``Event`` instance.
Parameters
``event_type``
can be either an ``EventType`` ... | [
"Convenience",
"function",
"to",
"create",
"an",
"Event",
"optionally",
"create",
"an",
"EventType",
"and",
"associated",
"Occurrence",
"s",
".",
"Occurrence",
"creation",
"rules",
"match",
"those",
"for",
"Event",
".",
"add_occurrences",
"."
] | d1cdd449bd5c6895c3ff182fd890c4d3452943fe | https://github.com/dakrauth/django-swingtime/blob/d1cdd449bd5c6895c3ff182fd890c4d3452943fe/swingtime/models.py#L208-L265 | train |
dakrauth/django-swingtime | swingtime/models.py | Event.add_occurrences | def add_occurrences(self, start_time, end_time, **rrule_params):
'''
Add one or more occurences to the event using a comparable API to
``dateutil.rrule``.
If ``rrule_params`` does not contain a ``freq``, one will be defaulted
to ``rrule.DAILY``.
Because ``rrule.rrule`` ... | python | def add_occurrences(self, start_time, end_time, **rrule_params):
'''
Add one or more occurences to the event using a comparable API to
``dateutil.rrule``.
If ``rrule_params`` does not contain a ``freq``, one will be defaulted
to ``rrule.DAILY``.
Because ``rrule.rrule`` ... | [
"def",
"add_occurrences",
"(",
"self",
",",
"start_time",
",",
"end_time",
",",
"*",
"*",
"rrule_params",
")",
":",
"count",
"=",
"rrule_params",
".",
"get",
"(",
"'count'",
")",
"until",
"=",
"rrule_params",
".",
"get",
"(",
"'until'",
")",
"if",
"not",... | Add one or more occurences to the event using a comparable API to
``dateutil.rrule``.
If ``rrule_params`` does not contain a ``freq``, one will be defaulted
to ``rrule.DAILY``.
Because ``rrule.rrule`` returns an iterator that can essentially be
unbounded, we need to slightly al... | [
"Add",
"one",
"or",
"more",
"occurences",
"to",
"the",
"event",
"using",
"a",
"comparable",
"API",
"to",
"dateutil",
".",
"rrule",
"."
] | d1cdd449bd5c6895c3ff182fd890c4d3452943fe | https://github.com/dakrauth/django-swingtime/blob/d1cdd449bd5c6895c3ff182fd890c4d3452943fe/swingtime/models.py#L84-L110 | train |
dakrauth/django-swingtime | swingtime/models.py | Event.daily_occurrences | def daily_occurrences(self, dt=None):
'''
Convenience method wrapping ``Occurrence.objects.daily_occurrences``.
'''
return Occurrence.objects.daily_occurrences(dt=dt, event=self) | python | def daily_occurrences(self, dt=None):
'''
Convenience method wrapping ``Occurrence.objects.daily_occurrences``.
'''
return Occurrence.objects.daily_occurrences(dt=dt, event=self) | [
"def",
"daily_occurrences",
"(",
"self",
",",
"dt",
"=",
"None",
")",
":",
"return",
"Occurrence",
".",
"objects",
".",
"daily_occurrences",
"(",
"dt",
"=",
"dt",
",",
"event",
"=",
"self",
")"
] | Convenience method wrapping ``Occurrence.objects.daily_occurrences``. | [
"Convenience",
"method",
"wrapping",
"Occurrence",
".",
"objects",
".",
"daily_occurrences",
"."
] | d1cdd449bd5c6895c3ff182fd890c4d3452943fe | https://github.com/dakrauth/django-swingtime/blob/d1cdd449bd5c6895c3ff182fd890c4d3452943fe/swingtime/models.py#L127-L131 | train |
dakrauth/django-swingtime | swingtime/models.py | OccurrenceManager.daily_occurrences | def daily_occurrences(self, dt=None, event=None):
'''
Returns a queryset of for instances that have any overlap with a
particular day.
* ``dt`` may be either a datetime.datetime, datetime.date object, or
``None``. If ``None``, default to the current day.
* ``event`` c... | python | def daily_occurrences(self, dt=None, event=None):
'''
Returns a queryset of for instances that have any overlap with a
particular day.
* ``dt`` may be either a datetime.datetime, datetime.date object, or
``None``. If ``None``, default to the current day.
* ``event`` c... | [
"def",
"daily_occurrences",
"(",
"self",
",",
"dt",
"=",
"None",
",",
"event",
"=",
"None",
")",
":",
"dt",
"=",
"dt",
"or",
"datetime",
".",
"now",
"(",
")",
"start",
"=",
"datetime",
"(",
"dt",
".",
"year",
",",
"dt",
".",
"month",
",",
"dt",
... | Returns a queryset of for instances that have any overlap with a
particular day.
* ``dt`` may be either a datetime.datetime, datetime.date object, or
``None``. If ``None``, default to the current day.
* ``event`` can be an ``Event`` instance for further filtering. | [
"Returns",
"a",
"queryset",
"of",
"for",
"instances",
"that",
"have",
"any",
"overlap",
"with",
"a",
"particular",
"day",
"."
] | d1cdd449bd5c6895c3ff182fd890c4d3452943fe | https://github.com/dakrauth/django-swingtime/blob/d1cdd449bd5c6895c3ff182fd890c4d3452943fe/swingtime/models.py#L136-L164 | train |
dakrauth/django-swingtime | swingtime/views.py | event_listing | def event_listing(
request,
template='swingtime/event_list.html',
events=None,
**extra_context
):
'''
View all ``events``.
If ``events`` is a queryset, clone it. If ``None`` default to all ``Event``s.
Context parameters:
``events``
an iterable of ``Event`` objects
...... | python | def event_listing(
request,
template='swingtime/event_list.html',
events=None,
**extra_context
):
'''
View all ``events``.
If ``events`` is a queryset, clone it. If ``None`` default to all ``Event``s.
Context parameters:
``events``
an iterable of ``Event`` objects
...... | [
"def",
"event_listing",
"(",
"request",
",",
"template",
"=",
"'swingtime/event_list.html'",
",",
"events",
"=",
"None",
",",
"*",
"*",
"extra_context",
")",
":",
"events",
"=",
"events",
"or",
"Event",
".",
"objects",
".",
"all",
"(",
")",
"extra_context",
... | View all ``events``.
If ``events`` is a queryset, clone it. If ``None`` default to all ``Event``s.
Context parameters:
``events``
an iterable of ``Event`` objects
... plus all values passed in via **extra_context | [
"View",
"all",
"events",
"."
] | d1cdd449bd5c6895c3ff182fd890c4d3452943fe | https://github.com/dakrauth/django-swingtime/blob/d1cdd449bd5c6895c3ff182fd890c4d3452943fe/swingtime/views.py#L20-L40 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.