Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fuchsia.googlesource.com-third_party-tink
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
fuchsia-mirror
fuchsia.googlesource.com-third_party-tink
Commits
ed8db752
Commit
ed8db752
authored
5 years ago
by
tanujdhir
Committed by
Copybara-Service
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Define Python Streaming AEAD.
PiperOrigin-RevId: 267113585
parent
6db4f184
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
python/streaming_aead/streaming_aead.py
+114
-0
114 additions, 0 deletions
python/streaming_aead/streaming_aead.py
with
114 additions
and
0 deletions
python/streaming_aead/streaming_aead.py
0 → 100644
+
114
−
0
View file @
ed8db752
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
This module defines the interface for Streaming AEAD.
"""
from
__future__
import
absolute_import
from
__future__
import
division
from
__future__
import
google_type_annotations
from
__future__
import
print_function
import
abc
from
typing
import
BinaryIO
class
StreamingAead
(
object
):
"""
The interface for streaming authenticated encryption with associated data.
Streaming encryption is typically used for encrypting large plaintexts such
as large files. This interface supports a streaming interface for symmetric
encryption with authentication. The underlying encryption modes are selected
so that partial plaintext can be obtained fast by decrypting and
authenticating just a part of the ciphertext.
"""
__metaclass__
=
abc
.
ABCMeta
@abc.abstractmethod
def
new_encrypting_stream
(
self
,
ciphertext_destination
:
BinaryIO
,
associated_data
:
bytes
)
->
BinaryIO
:
"""
Get a new encrypting stream that writes to ciphertext_destination.
Args:
ciphertext_destination: A writable binary file object to which ciphertext
will be written. It must support write(), close(), closed, and
writable().
associated_data: Associated data to be used by the AEAD encryption. It is
not included in the ciphertext and must be passed in as a parameter for
decryption.
Returns:
An encrypting file object wrapper around
'
ciphertext_destination
'
, such
that any bytes written to the wrapper are AEAD-encrypted using
'
associated_data
'
as associated authenticated data.
It supports the following:
write()
close()
closed
tell()
isatty()
flush() (no-op)
writable()
readable()
seekable()
__enter__() and __exit__()
Other methods, including read() and seek(), raise io.UnsupportedOperation.
Closing the wrapper also closes the ciphertext_destination.
Raises:
tink.TinkError if the creation fails.
"""
raise
NotImplementedError
()
@abc.abstractmethod
def
new_decrypting_stream
(
self
,
ciphertext_source
:
BinaryIO
,
associated_data
:
bytes
)
->
BinaryIO
:
"""
Get a new decrypting stream that reads from ciphertext_source.
Args:
ciphertext_source: A readable binary file object from which ciphertext
will be read.
associated_data: Associated data to be used by the AEAD decryption. It
must match the associated_data supplied for the encryption.
Returns:
A decrypting file object wrapper around
'
ciphertext_source
'
, such that
any bytes read from the wrapper are AEAD-decrypted using
'
associated_data
'
as associated authenticated data.
It supports the following:
read()
read1()
readinto()
readinto1()
readline()
readlines()
readall()
close()
closed
tell()
isatty()
flush() (no-op)
readable()
writable()
seekable()
__enter__() and __exit__()
__iter__() and __next__()
Other methods, including write() and seek(), raise
io.UnsupportedOperation.
Closing the wrapper also closes the ciphertext_source.
Raises:
tink.TinkError if the creation fails.
"""
raise
NotImplementedError
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment