Files
ServerSync/lib/nacl/__pycache__/secret.cpython-314.pyc

172 lines
14 KiB
Plaintext
Raw Normal View History

2026-02-12 02:28:23 +02:00
+
u<10>iX/<00><00><><00>^RIHtHt^RIt^RIHt^RIHt^RIH t H
t
H t !RR]P]
4t !RR ]P]
4tR#)
<EFBFBD>)<02>ClassVar<61>OptionalN)<01>encoding)<01>
exceptions)<03>EncryptedMessage<67> StringFixer<65>randomc<00>za<00>]tRt^toRt]P Pt]P Pt
]P Pt ]P Pt]P 3V3RlRlltV3RlRltR]P 3V3RlRlltR]P 3V3R lR
lltV3R ltR tVtR#) <0A> SecretBoxu<78>
The SecretBox class encrypts and decrypts messages using the given secret
key.
The ciphertexts generated by :class:`~nacl.secret.Secretbox` include a 16
byte authenticator which is checked as part of the decryption. An invalid
authenticator will cause the decrypt function to raise an exception. The
authenticator is not a signature. Once you've decrypted the message you've
demonstrated the ability to create arbitrary valid message, so messages you
send are repudiable. For non-repudiable messages, sign them after
encryption.
Encryption is done using `XSalsa20-Poly1305`_, and there are no practical
limits on the number or size of messages (up to 2⁶⁴ messages, each up to 2⁶⁴
bytes).
.. _XSalsa20-Poly1305: https://doc.libsodium.org/secret-key_cryptography/secretbox#algorithm-details
:param key: The secret key used to encrypt and decrypt messages
:param encoder: The encoder class used to decode the given key
:cvar KEY_SIZE: The size that the key is required to be.
:cvar NONCE_SIZE: The size that the nonce is required to be.
:cvar MACBYTES: The size of the authentication MAC tag in bytes.
:cvar MESSAGEBYTES_MAX: The maximum size of a message which can be
safely encrypted with a single key/nonce
pair.
c<00>:<<01>V^8<>dQhRS[RS[P/#<00><03><00>key<65>encoder<65><03>bytesr<00>Encoder)<02>format<61> __classdict__s"<22><>2/tmp/pip-target-zhdecbcm/lib/python/nacl/secret.py<70> __annotate__<5F>SecretBox.__annotate__;s#<00><><00> <18> <18><18> <18>#+<2B>#3<>#3<> <18>c<08><00>VPV4p\V\4'g\P!R4h\ V4VP 8wd(\P!RVP ,4hWnR#)z'SecretBox must be created from 32 bytes<65>%The key must be exactly %s bytes longN<67> <09>decode<64>
isinstancer<00>exc<78> TypeError<6F>len<65>KEY_SIZE<5A>
ValueError<EFBFBD>_key<65><03>selfrrs&&&r<00>__init__<5F>SecretBox.__init__;sc<00><00><16>n<EFBFBD>n<EFBFBD>S<EFBFBD>!<21><03><19>#<23>u<EFBFBD>%<25>%<25><15>-<2D>-<2D> I<>J<> J<> <0E>s<EFBFBD>8<EFBFBD>t<EFBFBD>}<7D>}<7D> $<24><15>.<2E>.<2E>7<>$<24>-<2D>-<2D>G<><0E> <0E><18> rc<00> <<01>V^8<>dQhRS[/#<00>r<00>return<72>r)rrs"<22>rrrI<00><00><><00><19><19>5<EFBFBD>rc<08><00>VP#<00>N<>r$<00>r&s&r<00> __bytes__<5F>SecretBox.__bytes__I<00> <00><00><13>y<EFBFBD>y<EFBFBD>rNc<00>V<<01>V^8<>dQhRS[RS[S[,RS[PRS[/#)r<00> plaintext<78>noncerr+<00>rrrrr)rrs"<22>rrrLs=<00><><00>)
<EFBFBD>)
<EFBFBD><18>)
<EFBFBD><18><05><EFBFBD>)
<EFBFBD><1A>!<21>!<21> )
<EFBFBD>
<1A> )
rc <0C><><00>Vf\VP4p\V4VP8wd(\P!RVP,4h\
P PWVP4pVPV4pVPV4p\P!VVVPW$,44#)a<>
Encrypts the plaintext message using the given `nonce` (or generates
one randomly if omitted) and returns the ciphertext encoded with the
encoder.
.. warning:: It is **VITALLY** important that the nonce is a nonce,
i.e. it is a number used only once for any given key. If you fail
to do this, you compromise the privacy of the messages encrypted.
Give your nonces a different prefix, or have one side use an odd
counter and one an even counter. Just make sure they are different.
:param plaintext: [:class:`bytes`] The plaintext message to encrypt
:param nonce: [:class:`bytes`] The nonce to use in the encryption
:param encoder: The encoder to use to encode the ciphertext
:rtype: [:class:`nacl.utils.EncryptedMessage`]
<EFBFBD>'The nonce must be exactly %s bytes long) r <00>
NONCE_SIZEr!rr#<00>nacl<63>bindings<67>crypto_secretbox_easyr$<00>encoder<00> _from_parts)r&r6r7r<00>
ciphertext<EFBFBD> encoded_nonce<63>encoded_ciphertexts&&&& r<00>encrypt<70>SecretBox.encryptLs<><00><00>, <11>=<3D><1A>4<EFBFBD>?<3F>?<3F>+<2B>E<EFBFBD> <0E>u<EFBFBD>:<3A><14><1F><1F> (<28><15>.<2E>.<2E>9<>D<EFBFBD>O<EFBFBD>O<EFBFBD>K<><0E> <0E><1A>]<5D>]<5D>8<>8<> <15>d<EFBFBD>i<EFBFBD>i<EFBFBD>
<EFBFBD>
<EFBFBD> <20><0E><0E>u<EFBFBD>-<2D> <0A>$<24>^<5E>^<5E>J<EFBFBD>7<><1A><1F>+<2B>+<2B> <19> <1E> <13>N<EFBFBD>N<EFBFBD>5<EFBFBD>-<2D> .<2E>
<EFBFBD>
rc<00>V<<01>V^8<>dQhRS[RS[S[,RS[PRS[/#)rrAr7rr+<00>rrrr)rrs"<22>rrrws=<00><><00>"<19>"<19><19>"<19><18><05><EFBFBD>"<19><1A>!<21>!<21> "<19>
<0F> "rc <0C>@<00>VPV4pVfVRVPpWPRp\V4VP8wd(\P!RVP,4h\
P PWVP4pV#<00>a<>
Decrypts the ciphertext using the `nonce` (explicitly, when passed as a
parameter or implicitly, when omitted, as part of the ciphertext) and
returns the plaintext message.
:param ciphertext: [:class:`bytes`] The encrypted message to decrypt
:param nonce: [:class:`bytes`] The nonce used when encrypting the
ciphertext
:param encoder: The encoder used to decode the ciphertext.
:rtype: [:class:`bytes`]
Nr:) rr;r!rr#r<r=<00>crypto_secretbox_open_easyr$)r&rAr7rr6s&&&& r<00>decrypt<70>SecretBox.decryptws<><00><00>$<1D>^<5E>^<5E>J<EFBFBD>/<2F>
<EFBFBD> <10>=<3D><1E>0<><14><1F><1F>1<>E<EFBFBD>#<23>O<EFBFBD>O<EFBFBD>$5<>6<>J<EFBFBD> <0E>u<EFBFBD>:<3A><14><1F><1F> (<28><15>.<2E>.<2E>9<>D<EFBFBD>O<EFBFBD>O<EFBFBD>K<><0E> <0E><19>M<EFBFBD>M<EFBFBD><<3C><<3C> <16>t<EFBFBD>y<EFBFBD>y<EFBFBD>
<EFBFBD> <09><19>rc<00><><<01>V^8<>dQh/S[S[,;R&S[S[,;R&S[S[,;R&S[S[,;R&#)rr"r;<00>MACBYTES<45>MESSAGEBYTES_MAX)r<00>int)rrs"<22>rrrsO<00><><00><00><<17>s<EFBFBD>m<EFBFBD>E<>=<01>><19><13> <0A>I<>?<01>@<17>s<EFBFBD>m<EFBFBD>E<>A<01>B<1F>s<EFBFBD>m<EFBFBD><06>Crr0)<18>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__firstlineno__<5F>__doc__r<r=<00>crypto_secretbox_KEYBYTESr"<00>crypto_secretbox_NONCEBYTESr;<00>crypto_secretbox_MACBYTESrN<00>!crypto_secretbox_MESSAGEBYTES_MAXrOr<00>
RawEncoderr'r2rDrK<00>__annotate_func__<5F>__static_attributes__<5F>__classdictcell__<5F>rs@rr r s<><00><><00><00><08>:#<23>m<EFBFBD>m<EFBFBD>E<>E<>H<EFBFBD> $<24> <0A> <0A> I<> I<>J<EFBFBD>"<22>m<EFBFBD>m<EFBFBD>E<>E<>H<EFBFBD> <0C> <0A> <0A>7<>7<><15>
7?<3F>6I<36>6I<36> <18> <18><19><19> "&<26>$,<2C>$7<>$7<> )
<EFBFBD>)
<EFBFBD>\"&<26>$,<2C>$7<>$7<> "<19>"<19>C<01>rr c<00>ra<00>]tRt^<5E>toRt]P Pt]P Pt
]P Pt ]P Pt]P 3V3RlRlltV3RlRltRR]P 3V3RlR lltRR]P 3V3R
lR lltR tVtR#) <0A>Aeadu<64>
The AEAD class encrypts and decrypts messages using the given secret key.
Unlike :class:`~nacl.secret.SecretBox`, AEAD supports authenticating
non-confidential data received alongside the message, such as a length
or type tag.
Like :class:`~nacl.secret.Secretbox`, this class provides authenticated
encryption. An inauthentic message will cause the decrypt function to raise
an exception.
Likewise, the authenticator should not be mistaken for a (public-key)
signature: recipients (with the ability to decrypt messages) are capable of
creating arbitrary valid message; in particular, this means AEAD messages
are repudiable. For non-repudiable messages, sign them after encryption.
The cryptosystem used is `XChacha20-Poly1305`_ as specified for
`standardization`_. There are `no practical limits`_ to how much can safely
be encrypted under a given key (up to 2⁶⁴ messages each containing up
to 2⁶⁴ bytes).
.. _standardization: https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-xchacha
.. _XChacha20-Poly1305: https://doc.libsodium.org/secret-key_cryptography/aead#xchacha-20-poly1305
.. _no practical limits: https://doc.libsodium.org/secret-key_cryptography/aead#limitations
:param key: The secret key used to encrypt and decrypt messages
:param encoder: The encoder class used to decode the given key
:cvar KEY_SIZE: The size that the key is required to be.
:cvar NONCE_SIZE: The size that the nonce is required to be.
:cvar MACBYTES: The size of the authentication MAC tag in bytes.
:cvar MESSAGEBYTES_MAX: The maximum size of a message which can be
safely encrypted with a single key/nonce
pair.
c<00>:<<01>V^8<>dQhRS[RS[P/#r r)rrs"<22>rr<00>Aead.__annotate__<5F>s%<00><><00><18><18> <12><18><1A>!<21>!<21>rc<08><00>VPV4p\V\4'g\P!R4h\ V4VP 8wd(\P!RVP ,4hWnR#)z"AEAD must be created from 32 bytesrNrr%s&&&rr'<00> Aead.__init__<5F>sc<00><00>
<16>n<EFBFBD>n<EFBFBD>S<EFBFBD>!<21><03><19>#<23>u<EFBFBD>%<25>%<25><15>-<2D>-<2D> D<>E<> E<> <0E>s<EFBFBD>8<EFBFBD>t<EFBFBD>}<7D>}<7D> $<24><15>.<2E>.<2E>7<>$<24>-<2D>-<2D>G<><0E> <0E><18> rc<00> <<01>V^8<>dQhRS[/#r*r,)rrs"<22>rrrb<00>r-rc<08><00>VP#r/r0r1s&rr2<00>Aead.__bytes__<5F>r4rrNc
<00>\<<01>V^8<>dQhRS[RS[RS[S[,RS[PRS[/#)rr6<00>aadr7rr+r8)rrs"<22>rrrb<00>sG<00><><00>1
<EFBFBD>1
<EFBFBD><18>1
<EFBFBD><13>1
<EFBFBD><18><05><EFBFBD> 1
<EFBFBD>
<1A>!<21>!<21> 1
<EFBFBD>
<1A> 1
rc <0C><><00>Vf\VP4p\V4VP8wd(\P!RVP,4h\
P PWW0P4pVPV4pVPV4p\P!VVVPW5,44#)a<>
Encrypts the plaintext message using the given `nonce` (or generates
one randomly if omitted) and returns the ciphertext encoded with the
encoder.
.. warning:: It is vitally important for :param nonce: to be unique.
By default, it is generated randomly; [:class:`Aead`] uses XChacha20
for extended (192b) nonce size, so the risk of reusing random nonces
is negligible. It is *strongly recommended* to keep this behaviour,
as nonce reuse will compromise the privacy of encrypted messages.
Should implicit nonces be inadequate for your application, the
second best option is using split counters; e.g. if sending messages
encrypted under a shared key between 2 users, each user can use the
number of messages it sent so far, prefixed or suffixed with a 1bit
user id. Note that the counter must **never** be rolled back (due
to overflow, on-disk state being rolled back to an earlier backup,
...)
:param plaintext: [:class:`bytes`] The plaintext message to encrypt
:param nonce: [:class:`bytes`] The nonce to use in the encryption
:param encoder: The encoder to use to encode the ciphertext
:rtype: [:class:`nacl.utils.EncryptedMessage`]
r:) r r;r!rr#r<r=<00>*crypto_aead_xchacha20poly1305_ietf_encryptr$r?rr@)r&r6rir7rrArBrCs&&&&& rrD<00> Aead.encrypt<70>s<><00><00>< <11>=<3D><1A>4<EFBFBD>?<3F>?<3F>+<2B>E<EFBFBD> <0E>u<EFBFBD>:<3A><14><1F><1F> (<28><15>.<2E>.<2E>9<>D<EFBFBD>O<EFBFBD>O<EFBFBD>K<><0E> <0E><1A>]<5D>]<5D>M<>M<> <15>E<EFBFBD>9<EFBFBD>9<EFBFBD>
<EFBFBD>
<EFBFBD> <20><0E><0E>u<EFBFBD>-<2D> <0A>$<24>^<5E>^<5E>J<EFBFBD>7<><1A><1F>+<2B>+<2B> <19> <1E> <13>N<EFBFBD>N<EFBFBD>5<EFBFBD>-<2D> .<2E>
<EFBFBD>
rc
<00>\<<01>V^8<>dQhRS[RS[RS[S[,RS[PRS[/#)rrArir7rr+rG)rrs"<22>rrrbsG<00><><00>#<19>#<19><19>#<19><13>#<19><18><05><EFBFBD> #<19>
<1A>!<21>!<21> #<19>
<0F> #rc <0C>@<00>VPV4pVfVRVPpWPRp\V4VP8wd(\P!RVP,4h\
P PWW0P4pV#rI) rr;r!rr#r<r=<00>*crypto_aead_xchacha20poly1305_ietf_decryptr$)r&rArir7rr6s&&&&& rrK<00> Aead.decrypts<><00><00>&<1D>^<5E>^<5E>J<EFBFBD>/<2F>
<EFBFBD> <10>=<3D><1E>0<><14><1F><1F>1<>E<EFBFBD>#<23>O<EFBFBD>O<EFBFBD>$5<>6<>J<EFBFBD> <0E>u<EFBFBD>:<3A><14><1F><1F> (<28><15>.<2E>.<2E>9<>D<EFBFBD>O<EFBFBD>O<EFBFBD>K<><0E> <0E><19>M<EFBFBD>M<EFBFBD>L<>L<> <16>U<EFBFBD>I<EFBFBD>I<EFBFBD>
<EFBFBD> <09><19>rr0)rQrRrSrTrUr<r=<00>+crypto_aead_xchacha20poly1305_ietf_KEYBYTESr"<00>,crypto_aead_xchacha20poly1305_ietf_NPUBBYTESr;<00>)crypto_aead_xchacha20poly1305_ietf_ABYTESrN<00>3crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAXrOrrZr'r2rDrKr\r]r^s@rr`r`<00>s<><00><><00><00>"<08>H<14>}<7D>}<7D>H<>H<>H<EFBFBD><15><1D><1D>K<>K<>J<EFBFBD><13>}<7D>}<7D>F<>F<>H<EFBFBD> <0C> <0A> <0A>I<>I<><15>%-<2D>$7<>$7<><18><18> <19><19> <19>!%<25>$,<2C>$7<>$7<> 1
<EFBFBD>1
<EFBFBD>l<19>!%<25>$,<2C>$7<>$7<> #<19>#<19>#rr`)<0F>typingrr<00> nacl.bindingsr<rrr<00>
nacl.utilsrrr <00> Encodabler r`<00>rr<00><module>rzsF<00><01>&<26><14><19>"<22><<3C><<3C>C<19><08>"<22>"<22>K<EFBFBD>C<19>LU<19>8<EFBFBD> <1D> <1D>{<7B>Ur