From 559b024e1d2d31edc0cf42db9eae1d0a97d92d24 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Tue, 7 Sep 2021 11:40:11 -0700 Subject: [PATCH] Decentralize Python native module linkage We can now link even smaller Python binaries. For example, the hello.com program in the Python build directory is a compiled linked executable of hello.py which just prints hello world. Using decentralized sections, we can make that binary 1.9mb in size (noting that python.com is 6.3 megs!) This works for nontrivial programs too. For example, say we want an APE binary that's equivalent to python.com -m http.server. Our makefile now builds such a binary using the new launcher and it's only 3.2mb in size since Python sources get turned into ELF objects, which tell our linker that we need things like native hashing algorithm code. --- ape/ape.lds | 3 + build/definitions.mk | 2 +- libc/nt/enum/fsctl.h | 1 + libc/nt/events.h | 28 +- libc/nt/files.h | 6 + libc/nt/ipc.h | 10 +- libc/nt/kernel32/CreateEventA.s | 10 + libc/nt/kernel32/CreateEventExA.s | 10 + libc/nt/kernel32/CreateEventExW.s | 10 + libc/nt/kernel32/CreateEventW.s | 10 + libc/nt/kernel32/GetOverlappedResult.s | 10 + libc/nt/kernel32/GetOverlappedResultEx.s | 10 + libc/nt/master.sh | 12 +- libc/nt/thread.h | 2 +- libc/str/blake2.c | 163 + libc/str/blake2.h | 29 + libc/str/crc32z.c | 2 + libc/str/getzipcdir.c | 2 +- libc/str/str.mk | 2 + libc/unicode/langinfo.c | 89 + libc/unicode/langinfo.h | 86 + test/libc/str/blake2_test.c | 90 + test/libc/str/blake2b256_tests.txt | 820 +++ test/libc/str/test.mk | 96 +- test/net/https/mbedtls_test.c | 4 + third_party/mbedtls/blake2b256.c | 33 + third_party/mbedtls/config.h | 4 +- third_party/mbedtls/md.c | 8 + third_party/mbedtls/md.h | 23 +- third_party/mbedtls/pem.c | 2 +- third_party/python/Include/import.h | 2 +- third_party/python/Include/pylifecycle.h | 1 + third_party/python/Lib/_bootlocale.py | 37 +- third_party/python/Lib/_strptime.py | 5 +- .../python/Lib/collections/__init__.py | 13 +- third_party/python/Lib/hashlib.py | 77 +- third_party/python/Lib/hello.py | 1 + .../Lib/importlib/_bootstrap_external.py | 2 +- third_party/python/Lib/launchpy.py | 15 + third_party/python/Lib/os.py | 5 +- third_party/python/Lib/pydoc.py | 11 +- third_party/python/Lib/shutil.py | 36 +- third_party/python/Modules/_bisectmodule.c | 6 + third_party/python/Modules/_bz2module.c | 6 + third_party/python/Modules/_codecsmodule.c | 1 + .../python/Modules/_collectionsmodule.c | 1 + third_party/python/Modules/_csv.c | 6 + third_party/python/Modules/_curses_panel.c | 552 -- third_party/python/Modules/_cursesmodule.c | 3522 ---------- third_party/python/Modules/_datetimemodule.c | 5 + .../python/Modules/_decimal/_decimal.c | 4 +- third_party/python/Modules/_elementtree.c | 5 + third_party/python/Modules/_functoolsmodule.c | 1 + .../{_hashopenssl.c => _hashmbedtls.c} | 151 +- third_party/python/Modules/_heapqmodule.c | 2 +- third_party/python/Modules/_json.c | 11 + third_party/python/Modules/_localemodule.c | 2 + third_party/python/Modules/_lsprof.c | 6 + .../_multiprocessing/multiprocessing.c | 5 + third_party/python/Modules/_opcode.c | 6 + third_party/python/Modules/_pickle.c | 7 + third_party/python/Modules/_posixsubprocess.c | 5 + third_party/python/Modules/_randommodule.c | 6 + third_party/python/Modules/_sha3.c | 165 +- third_party/python/Modules/_sqlite/module.c | 5 + third_party/python/Modules/_ssl.c | 5713 ----------------- third_party/python/Modules/_ssl_data.inc | 1940 +----- third_party/python/Modules/_stat.c | 6 + third_party/python/Modules/_struct.c | 6 + third_party/python/Modules/_testcapimodule.c | 8 + third_party/python/Modules/_tracemalloc.c | 6 + third_party/python/Modules/_weakref.c | 1 + third_party/python/Modules/_winapi.c | 486 +- third_party/python/Modules/arraymodule.c | 5 + third_party/python/Modules/atexitmodule.c | 6 + third_party/python/Modules/audioop.c | 6 + third_party/python/Modules/binascii.c | 6 + .../python/Modules/cjkcodecs/_codecs_cn.c | 6 + .../python/Modules/cjkcodecs/_codecs_hk.c | 6 + .../Modules/cjkcodecs/_codecs_iso2022.c | 6 + .../python/Modules/cjkcodecs/_codecs_jp.c | 6 + .../python/Modules/cjkcodecs/_codecs_kr.c | 6 + .../python/Modules/cjkcodecs/_codecs_tw.c | 6 + .../python/Modules/cjkcodecs/multibytecodec.c | 6 + .../{_hashopenssl.inc => _hashmbedtls.inc} | 0 third_party/python/Modules/clinic/_winapi.inc | 236 +- third_party/python/Modules/cmathmodule.c | 6 + third_party/python/Modules/config.c | 267 +- third_party/python/Modules/errnomodule.c | 1 + third_party/python/Modules/faulthandler.c | 5 + third_party/python/Modules/fcntlmodule.c | 6 + third_party/python/Modules/fpectlmodule.c | 6 + third_party/python/Modules/getpath.c | 17 +- third_party/python/Modules/grpmodule.c | 6 + third_party/python/Modules/hashtable.c | 5 + third_party/python/Modules/itertoolsmodule.c | 1 + third_party/python/Modules/mathmodule.c | 6 + third_party/python/Modules/md5module.c | 6 + third_party/python/Modules/mmapmodule.c | 6 + third_party/python/Modules/parsermodule.c | 5 + third_party/python/Modules/posixmodule.c | 4 + third_party/python/Modules/pwdmodule.c | 6 + third_party/python/Modules/pyexpat.c | 9 + third_party/python/Modules/resource.c | 6 + third_party/python/Modules/selectmodule.c | 6 + third_party/python/Modules/sha1module.c | 6 + third_party/python/Modules/sha256module.c | 6 + third_party/python/Modules/sha512module.c | 6 + third_party/python/Modules/socketmodule.c | 6 + third_party/python/Modules/symtablemodule.c | 6 + third_party/python/Modules/syslogmodule.c | 12 + third_party/python/Modules/termios.c | 6 + third_party/python/Modules/timemodule.c | 7 + third_party/python/Modules/unicodedata.c | 6 + third_party/python/Modules/winreparse.h | 61 +- third_party/python/Modules/zipimport.c | 9 + third_party/python/Modules/zlibmodule.c | 6 + third_party/python/Objects/unicodeobject.c | 729 --- third_party/python/Programs/hello.c | 2 + third_party/python/Programs/httpserver.c | 4 +- third_party/python/Programs/launch.c | 143 + third_party/python/Programs/python.c | 24 - .../python/Python/importlib_external.inc | 2 +- third_party/python/Python/pylifecycle.c | 23 +- third_party/python/pycomp.c | 3 + third_party/python/pyconfig.h | 3 + third_party/python/pyobj.c | 5 +- third_party/python/python.mk | 24 +- tool/net/redbean.c | 110 +- 129 files changed, 2798 insertions(+), 13514 deletions(-) create mode 100644 libc/str/blake2.c create mode 100644 libc/str/blake2.h create mode 100644 libc/unicode/langinfo.c create mode 100644 libc/unicode/langinfo.h create mode 100644 test/libc/str/blake2_test.c create mode 100644 test/libc/str/blake2b256_tests.txt create mode 100644 third_party/mbedtls/blake2b256.c create mode 100644 third_party/python/Lib/hello.py create mode 100644 third_party/python/Lib/launchpy.py delete mode 100644 third_party/python/Modules/_curses_panel.c delete mode 100644 third_party/python/Modules/_cursesmodule.c rename third_party/python/Modules/{_hashopenssl.c => _hashmbedtls.c} (88%) delete mode 100644 third_party/python/Modules/_ssl.c rename third_party/python/Modules/clinic/{_hashopenssl.inc => _hashmbedtls.inc} (100%) create mode 100644 third_party/python/Programs/hello.c create mode 100644 third_party/python/Programs/launch.c diff --git a/ape/ape.lds b/ape/ape.lds index 794109bf4..b772862b6 100644 --- a/ape/ape.lds +++ b/ape/ape.lds @@ -289,6 +289,9 @@ SECTIONS { /*BEGIN: Read Only Data */ KEEP(*(.ape.pad.rodata)); + KEEP(*(.rodata.pytab.0)); + KEEP(*(.rodata.pytab.1)); + KEEP(*(.rodata.pytab.2)); *(.rodata .rodata.*) *(.ubsan.types) diff --git a/build/definitions.mk b/build/definitions.mk index b86775fca..e431d373f 100644 --- a/build/definitions.mk +++ b/build/definitions.mk @@ -168,7 +168,7 @@ DEFAULT_LDFLAGS = \ --gc-sections \ --build-id=none \ --no-dynamic-linker \ - -z max-page-size=0x1000 + -z max-page-size=0x1000 --cref -Map=$@.map ZIPOBJ_FLAGS = \ -b$(IMAGE_BASE_VIRTUAL) diff --git a/libc/nt/enum/fsctl.h b/libc/nt/enum/fsctl.h index 0c7424147..8da9b2f1e 100644 --- a/libc/nt/enum/fsctl.h +++ b/libc/nt/enum/fsctl.h @@ -13,5 +13,6 @@ #define kNtFsctlSetSparse 0x000900C4u #define kNtFsctlSetZeroData 0x000980C8u #define kNtFsctlGetReparsePoint 0x000900a8u +#define kNtFsctlSetReparsePoint 0x000900a4u #endif /* COSMOPOLITAN_LIBC_NT_ENUM_FSCTL_H_ */ diff --git a/libc/nt/events.h b/libc/nt/events.h index 8530bc22b..d8a60fedf 100644 --- a/libc/nt/events.h +++ b/libc/nt/events.h @@ -2,6 +2,7 @@ #define COSMOPOLITAN_LIBC_NT_EVENTS_H_ #include "libc/nt/struct/msg.h" #include "libc/nt/struct/point.h" +#include "libc/nt/struct/securityattributes.h" /* ░░░░ ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ @@ -39,19 +40,28 @@ bool32 GetCursorPos(struct NtPoint *lpPoint); int64_t SendMessage(int64_t hWnd, uint32_t Msg, uint64_t wParam, int64_t lParam); -#define EVENTLOG_SUCCESS 0x00000000 -#define EVENTLOG_ERROR_TYPE 0x00000001 -#define EVENTLOG_WARNING_TYPE 0x00000002 -#define EVENTLOG_INFORMATION_TYPE 0x00000004 -#define EVENTLOG_AUDIT_SUCCESS 0x00000008 -#define EVENTLOG_AUDIT_FAILURE 0x00000010 +#define EVENTLOG_SUCCESS 0x00000000 +#define EVENTLOG_ERROR_TYPE 0x00000001 +#define EVENTLOG_WARNING_TYPE 0x00000002 +#define EVENTLOG_INFORMATION_TYPE 0x00000004 +#define EVENTLOG_AUDIT_SUCCESS 0x00000008 +#define EVENTLOG_AUDIT_FAILURE 0x00000010 int32_t ReportEventA(int64_t handle, uint16_t wType, uint16_t wCategory, - uint32_t dwEventID, const char *lpUserId, uint16_t wNumStrings, - uint32_t dwDataSize, const char **lpStrings, void **lpRawData); -int64_t RegisterEventSourceA(const char *lpUNCServerName, const char *lpSourceName); + uint32_t dwEventID, const char *lpUserId, + uint16_t wNumStrings, uint32_t dwDataSize, + const char **lpStrings, void **lpRawData); +int64_t RegisterEventSourceA(const char *lpUNCServerName, + const char *lpSourceName); int32_t DeregisterEventSource(uint64_t handle); +int64_t CreateEvent(struct NtSecurityAttributes *lpEventAttributes, + bool32 bManualReset, bool32 bInitialState, + const char16_t *lpName); +int64_t CreateEventEx(struct NtSecurityAttributes *lpEventAttributes, + const char16_t *lpName, uint32_t dwFlags, + uint32_t dwDesiredAccess); + COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_EVENTS_H_ */ diff --git a/libc/nt/files.h b/libc/nt/files.h index 2e4da169f..52f2fe997 100644 --- a/libc/nt/files.h +++ b/libc/nt/files.h @@ -211,6 +211,12 @@ uint32_t GetFinalPathNameByHandle(int64_t hFile, char16_t *out_path, uint32_t GetFullPathName(const char16_t *lpFileName, uint32_t nBufferLength, char16_t *lpBuffer, char16_t **lpFilePart); +bool32 GetOverlappedResult(int64_t hFile, struct NtOverlapped *lpOverlapped, + uint32_t *lpNumberOfBytesTransferred, bool32 bWait); +bool32 GetOverlappedResultEx(int64_t hFile, struct NtOverlapped *lpOverlapped, + uint32_t *lpNumberOfBytesTransferred, + uint32_t dwMilliseconds, bool32 bAlertable); + #if ShouldUseMsabiAttribute() #include "libc/nt/thunk/files.inc" #endif /* ShouldUseMsabiAttribute() */ diff --git a/libc/nt/ipc.h b/libc/nt/ipc.h index da6a7a7ad..2c79321c9 100644 --- a/libc/nt/ipc.h +++ b/libc/nt/ipc.h @@ -68,19 +68,19 @@ bool32 CallNamedPipe(const char16_t *lpNamedPipeName, void *lpInBuffer, uint32_t nOutBufferSize, uint32_t *lpBytesRead, uint32_t nTimeOut); -bool32 ConnectNamedPipe(int64_t *hNamedPipe, struct NtOverlapped *lpOverlapped); +bool32 ConnectNamedPipe(int64_t hNamedPipe, struct NtOverlapped *lpOverlapped); bool32 WaitNamedPipe(const char16_t *lpNamedPipeName, uint32_t nTimeOut); -bool32 DisconnectNamedPipe(int64_t *hNamedPipe); +bool32 DisconnectNamedPipe(int64_t hNamedPipe); -bool32 SetNamedPipeHandleState(int64_t *hNamedPipe, uint32_t *lpMode, +bool32 SetNamedPipeHandleState(int64_t hNamedPipe, uint32_t *lpMode, uint32_t *lpMaxCollectionCount, uint32_t *lpCollectDataTimeout); -bool32 PeekNamedPipe(int64_t *hNamedPipe, void *lpBuffer, uint32_t nBufferSize, +bool32 PeekNamedPipe(int64_t hNamedPipe, void *lpBuffer, uint32_t nBufferSize, uint32_t *lpBytesRead, uint32_t *lpTotalBytesAvail, uint32_t *lpBytesLeftThisMessage); -bool32 TransactNamedPipe(int64_t *hNamedPipe, void *lpInBuffer, +bool32 TransactNamedPipe(int64_t hNamedPipe, void *lpInBuffer, uint32_t nInBufferSize, void *lpOutBuffer, uint32_t nOutBufferSize, uint32_t *lpBytesRead, struct NtOverlapped *lpOverlapped); diff --git a/libc/nt/kernel32/CreateEventA.s b/libc/nt/kernel32/CreateEventA.s index cad1a9bef..6b556c040 100644 --- a/libc/nt/kernel32/CreateEventA.s +++ b/libc/nt/kernel32/CreateEventA.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp kernel32,__imp_CreateEventA,CreateEventA,0 + + .text.windows +CreateEventA: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_CreateEventA(%rip),%rax + jmp __sysv2nt + .endfn CreateEventA,globl + .previous diff --git a/libc/nt/kernel32/CreateEventExA.s b/libc/nt/kernel32/CreateEventExA.s index df111f3b6..bd70e5fd2 100644 --- a/libc/nt/kernel32/CreateEventExA.s +++ b/libc/nt/kernel32/CreateEventExA.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp kernel32,__imp_CreateEventExA,CreateEventExA,0 + + .text.windows +CreateEventExA: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_CreateEventExA(%rip),%rax + jmp __sysv2nt + .endfn CreateEventExA,globl + .previous diff --git a/libc/nt/kernel32/CreateEventExW.s b/libc/nt/kernel32/CreateEventExW.s index c72a2f9e9..04241690d 100644 --- a/libc/nt/kernel32/CreateEventExW.s +++ b/libc/nt/kernel32/CreateEventExW.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp kernel32,__imp_CreateEventExW,CreateEventExW,0 + + .text.windows +CreateEventEx: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_CreateEventExW(%rip),%rax + jmp __sysv2nt + .endfn CreateEventEx,globl + .previous diff --git a/libc/nt/kernel32/CreateEventW.s b/libc/nt/kernel32/CreateEventW.s index 0e7b6d136..7cd7901b3 100644 --- a/libc/nt/kernel32/CreateEventW.s +++ b/libc/nt/kernel32/CreateEventW.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp kernel32,__imp_CreateEventW,CreateEventW,0 + + .text.windows +CreateEvent: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_CreateEventW(%rip),%rax + jmp __sysv2nt + .endfn CreateEvent,globl + .previous diff --git a/libc/nt/kernel32/GetOverlappedResult.s b/libc/nt/kernel32/GetOverlappedResult.s index 7a19a030b..df0a13669 100644 --- a/libc/nt/kernel32/GetOverlappedResult.s +++ b/libc/nt/kernel32/GetOverlappedResult.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp kernel32,__imp_GetOverlappedResult,GetOverlappedResult,0 + + .text.windows +GetOverlappedResult: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_GetOverlappedResult(%rip),%rax + jmp __sysv2nt + .endfn GetOverlappedResult,globl + .previous diff --git a/libc/nt/kernel32/GetOverlappedResultEx.s b/libc/nt/kernel32/GetOverlappedResultEx.s index a3cfcf74a..10c65178f 100644 --- a/libc/nt/kernel32/GetOverlappedResultEx.s +++ b/libc/nt/kernel32/GetOverlappedResultEx.s @@ -1,2 +1,12 @@ .include "o/libc/nt/codegen.inc" .imp kernel32,__imp_GetOverlappedResultEx,GetOverlappedResultEx,0 + + .text.windows +GetOverlappedResultEx: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_GetOverlappedResultEx(%rip),%rax + jmp __sysv2nt6 + .endfn GetOverlappedResultEx,globl + .previous diff --git a/libc/nt/master.sh b/libc/nt/master.sh index 99a6fe8cf..b614bd57e 100755 --- a/libc/nt/master.sh +++ b/libc/nt/master.sh @@ -587,10 +587,10 @@ imp 'CreateEllipticRgnIndirect' CreateEllipticRgnIndirect gdi32 1074 imp 'CreateEnclave' CreateEnclave KernelBase 180 imp 'CreateEnhMetaFileA' CreateEnhMetaFileA gdi32 1075 imp 'CreateEnhMetaFile' CreateEnhMetaFileW gdi32 1076 -imp 'CreateEventA' CreateEventA kernel32 0 # KernelBase -imp 'CreateEventExA' CreateEventExA kernel32 0 # KernelBase -imp 'CreateEventEx' CreateEventExW kernel32 0 # KernelBase -imp 'CreateEvent' CreateEventW kernel32 0 # KernelBase +imp 'CreateEventA' CreateEventA kernel32 0 4 # KernelBase +imp 'CreateEventExA' CreateEventExA kernel32 0 4 # KernelBase +imp 'CreateEventEx' CreateEventExW kernel32 0 4 # KernelBase +imp 'CreateEvent' CreateEventW kernel32 0 4 # KernelBase imp 'CreateFiber' CreateFiber kernel32 0 # KernelBase imp 'CreateFiberEx' CreateFiberEx kernel32 0 # KernelBase imp 'CreateFile' CreateFileW kernel32 0 7 # KernelBase @@ -2384,8 +2384,8 @@ imp 'GetOsSafeBootMode' GetOsSafeBootMode KernelBase 626 imp 'GetOutlineTextMetricsA' GetOutlineTextMetricsA gdi32 1685 imp 'GetOutlineTextMetrics' GetOutlineTextMetricsW gdi32 1686 imp 'GetOverlappedAccessResults' GetOverlappedAccessResults advapi32 1348 -imp 'GetOverlappedResult' GetOverlappedResult kernel32 0 # KernelBase -imp 'GetOverlappedResultEx' GetOverlappedResultEx kernel32 0 # KernelBase +imp 'GetOverlappedResult' GetOverlappedResult kernel32 0 4 # KernelBase +imp 'GetOverlappedResultEx' GetOverlappedResultEx kernel32 0 5 # KernelBase imp 'GetPackageApplicationContext' GetPackageApplicationContext KernelBase 629 imp 'GetPackageApplicationIds' GetPackageApplicationIds kernel32 0 # KernelBase imp 'GetPackageApplicationProperty' GetPackageApplicationProperty KernelBase 631 diff --git a/libc/nt/thread.h b/libc/nt/thread.h index 700777812..d5a8c3548 100644 --- a/libc/nt/thread.h +++ b/libc/nt/thread.h @@ -55,7 +55,7 @@ bool32 GetThreadIOPendingFlag(int64_t hThread, bool32 *lpIOIsPending); bool32 CancelSynchronousIo(int64_t hThread); bool32 CancelIo(int64_t hFile); -bool32 CancelIoEx(int64_t hFile, struct NtOverlapped opt_lpOverlapped); +bool32 CancelIoEx(int64_t hFile, struct NtOverlapped *opt_lpOverlapped); #if ShouldUseMsabiAttribute() #include "libc/nt/thunk/thread.inc" diff --git a/libc/str/blake2.c b/libc/str/blake2.c new file mode 100644 index 000000000..cc8f490fe --- /dev/null +++ b/libc/str/blake2.c @@ -0,0 +1,163 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Google LLC │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/assert.h" +#include "libc/macros.internal.h" +#include "libc/str/blake2.h" +#include "libc/str/str.h" + +#define ROR(v, n) (((v) >> (n)) | ((v) << (64 - (n)))) + +asm(".ident\t\"\\n\\n\ +boringssl blake2b (ISC License)\\n\ +Copyright 2021 Google LLC\""); +asm(".include \"libc/disclaimer.inc\""); + +// https://tools.ietf.org/html/rfc7693#section-2.6 +static const uint64_t kIV[8] = { + 0x6a09e667f3bcc908, 0xbb67ae8584caa73b, 0x3c6ef372fe94f82b, + 0xa54ff53a5f1d36f1, 0x510e527fade682d1, 0x9b05688c2b3e6c1f, + 0x1f83d9abfb41bd6b, 0x5be0cd19137e2179, +}; + +// https://tools.ietf.org/html/rfc7693#section-2.7 +static const uint8_t kSigma[10][16] = { + // clang-format off + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, + {14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3}, + {11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4}, + {7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8}, + {9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13}, + {2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9}, + {12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11}, + {13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10}, + {6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5}, + {10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0}, + // clang-format on +}; + +// https://tools.ietf.org/html/rfc7693#section-3.1 +static void Blake2bMix(uint64_t v[16], int a, int b, int c, int d, uint64_t x, + uint64_t y) { + v[a] = v[a] + v[b] + x; + v[d] = ROR(v[d] ^ v[a], 32); + v[c] = v[c] + v[d]; + v[b] = ROR(v[b] ^ v[c], 24); + v[a] = v[a] + v[b] + y; + v[d] = ROR(v[d] ^ v[a], 16); + v[c] = v[c] + v[d]; + v[b] = ROR(v[b] ^ v[c], 63); +} + +static void Blake2bTransform( + struct Blake2b *b2b, const uint64_t w[BLAKE2B_CBLOCK / sizeof(uint64_t)], + size_t num_bytes, int is_final_block) { + // https://tools.ietf.org/html/rfc7693#section-3.2 + uint64_t v[16]; + _Static_assert(sizeof(v) == sizeof(b2b->h) + sizeof(kIV), ""); + memcpy(v, b2b->h, sizeof(b2b->h)); + memcpy(&v[8], kIV, sizeof(kIV)); + b2b->t_low += num_bytes; + if (b2b->t_low < num_bytes) { + b2b->t_high++; + } + v[12] ^= b2b->t_low; + v[13] ^= b2b->t_high; + if (is_final_block) { + v[14] = ~v[14]; + } + for (int i = 0; i < 12; i++) { + Blake2bMix(v, 0, 4, 8, 12, w[kSigma[i % 10][0]], w[kSigma[i % 10][1]]); + Blake2bMix(v, 1, 5, 9, 13, w[kSigma[i % 10][2]], w[kSigma[i % 10][3]]); + Blake2bMix(v, 2, 6, 10, 14, w[kSigma[i % 10][4]], w[kSigma[i % 10][5]]); + Blake2bMix(v, 3, 7, 11, 15, w[kSigma[i % 10][6]], w[kSigma[i % 10][7]]); + Blake2bMix(v, 0, 5, 10, 15, w[kSigma[i % 10][8]], w[kSigma[i % 10][9]]); + Blake2bMix(v, 1, 6, 11, 12, w[kSigma[i % 10][10]], w[kSigma[i % 10][11]]); + Blake2bMix(v, 2, 7, 8, 13, w[kSigma[i % 10][12]], w[kSigma[i % 10][13]]); + Blake2bMix(v, 3, 4, 9, 14, w[kSigma[i % 10][14]], w[kSigma[i % 10][15]]); + } + for (size_t i = 0; i < ARRAYLEN(b2b->h); i++) { + b2b->h[i] ^= v[i]; + b2b->h[i] ^= v[i + 8]; + } +} + +int BLAKE2B256_Init(struct Blake2b *b2b) { + bzero(b2b, sizeof(struct Blake2b)); + _Static_assert(sizeof(kIV) == sizeof(b2b->h), ""); + memcpy(&b2b->h, kIV, sizeof(kIV)); + // https://tools.ietf.org/html/rfc7693#section-2.5 + b2b->h[0] ^= 0x01010000 | BLAKE2B256_DIGEST_LENGTH; + return 0; +} + +int BLAKE2B256_Process(struct Blake2b *b2b, + const uint64_t data[BLAKE2B_CBLOCK / 8]) { + Blake2bTransform(b2b, data, BLAKE2B_CBLOCK, /*is_final_block=*/0); + return 0; +} + +int BLAKE2B256_Update(struct Blake2b *b2b, const void *in_data, size_t len) { + const uint8_t *data = (const uint8_t *)in_data; + size_t todo = sizeof(b2b->block.bytes) - b2b->block_used; + if (todo > len) { + todo = len; + } + memcpy(&b2b->block.bytes[b2b->block_used], data, todo); + b2b->block_used += todo; + data += todo; + len -= todo; + if (!len) { + return 0; + } + // More input remains therefore we must have filled |b2b->block|. + assert(b2b->block_used == BLAKE2B_CBLOCK); + Blake2bTransform(b2b, b2b->block.words, BLAKE2B_CBLOCK, + /*is_final_block=*/0); + b2b->block_used = 0; + while (len > BLAKE2B_CBLOCK) { + uint64_t block_words[BLAKE2B_CBLOCK / sizeof(uint64_t)]; + memcpy(block_words, data, sizeof(block_words)); + Blake2bTransform(b2b, block_words, BLAKE2B_CBLOCK, /*is_final_block=*/0); + data += BLAKE2B_CBLOCK; + len -= BLAKE2B_CBLOCK; + } + memcpy(b2b->block.bytes, data, len); + b2b->block_used = len; + return 0; +} + +int BLAKE2B256_Final(struct Blake2b *b2b, + uint8_t out[BLAKE2B256_DIGEST_LENGTH]) { + bzero(&b2b->block.bytes[b2b->block_used], + sizeof(b2b->block.bytes) - b2b->block_used); + Blake2bTransform(b2b, b2b->block.words, b2b->block_used, + /*is_final_block=*/1); + _Static_assert(BLAKE2B256_DIGEST_LENGTH <= sizeof(b2b->h), ""); + memcpy(out, b2b->h, BLAKE2B256_DIGEST_LENGTH); + return 0; +} + +int BLAKE2B256(const void *data, size_t len, + uint8_t out[BLAKE2B256_DIGEST_LENGTH]) { + struct Blake2b ctx; + BLAKE2B256_Init(&ctx); + BLAKE2B256_Update(&ctx, data, len); + BLAKE2B256_Final(&ctx, out); + return 0; +} diff --git a/libc/str/blake2.h b/libc/str/blake2.h new file mode 100644 index 000000000..f99e5622a --- /dev/null +++ b/libc/str/blake2.h @@ -0,0 +1,29 @@ +#ifndef COSMOPOLITAN_LIBC_STR_BLAKE2_H_ +#define COSMOPOLITAN_LIBC_STR_BLAKE2_H_ + +#define BLAKE2B256_DIGEST_LENGTH 32 +#define BLAKE2B_CBLOCK 128 + +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +struct Blake2b { + uint64_t h[8]; + uint64_t t_low; + uint64_t t_high; + union { + uint8_t bytes[BLAKE2B_CBLOCK]; + uint64_t words[16]; + } block; + size_t block_used; +}; + +int BLAKE2B256_Init(struct Blake2b *); +int BLAKE2B256_Update(struct Blake2b *, const void *, size_t); +int BLAKE2B256_Process(struct Blake2b *, const uint64_t[BLAKE2B_CBLOCK / 8]); +int BLAKE2B256_Final(struct Blake2b *, uint8_t[BLAKE2B256_DIGEST_LENGTH]); +int BLAKE2B256(const void *, size_t, uint8_t[BLAKE2B256_DIGEST_LENGTH]); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_STR_BLAKE2_H_ */ diff --git a/libc/str/crc32z.c b/libc/str/crc32z.c index 683e5f7bd..947c0a9f2 100644 --- a/libc/str/crc32z.c +++ b/libc/str/crc32z.c @@ -29,6 +29,8 @@ static uint32_t kCrc32Tab[256]; * 0b100000100110000010001110110110111 * bitreverse32(0x104c11db7) * + * This implementation takes 32 picoseconds per byte or 30 gibibyte/s. + * * @param h is initial value */ uint32_t crc32_z(uint32_t h, const void *data, size_t size) { diff --git a/libc/str/getzipcdir.c b/libc/str/getzipcdir.c index 82c73b02b..2c12637da 100644 --- a/libc/str/getzipcdir.c +++ b/libc/str/getzipcdir.c @@ -47,7 +47,7 @@ void *GetZipCdir(const uint8_t *p, size_t n) { IsZipCdir64(p, n, ZIP_LOCATE64_OFFSET(p + j))) { return p + ZIP_LOCATE64_OFFSET(p + j); } - } while (j-- && i - j < 1024); + } while (j-- && i - j < 128); return p + i; } } while (i--); diff --git a/libc/str/str.mk b/libc/str/str.mk index 5015a640f..c59be2fb9 100644 --- a/libc/str/str.mk +++ b/libc/str/str.mk @@ -52,6 +52,8 @@ o//libc/str/bzero.o: \ OVERRIDE_CFLAGS += \ -O2 +o/$(MODE)/libc/str/fun3.o \ +o/$(MODE)/libc/str/sha3.o \ o/$(MODE)/libc/str/dosdatetimetounix.o: \ OVERRIDE_CFLAGS += \ -O3 diff --git a/libc/unicode/langinfo.c b/libc/unicode/langinfo.c new file mode 100644 index 000000000..7166edb9a --- /dev/null +++ b/libc/unicode/langinfo.c @@ -0,0 +1,89 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/unicode/langinfo.h" + +static const char c_time[] = "\ +Sun\0\n\ +Mon\0\n\ +Tue\0\n\ +Wed\0\n\ +Thu\0\n\ +Fri\0\n\ +Sat\0\n\ +Sunday\0\n\ +Monday\0\n\ +Tuesday\0\n\ +Wednesday\0\n\ +Thursday\0\n\ +Friday\0\n\ +Saturday\0\n\ +Jan\0\n\ +Feb\0\n\ +Mar\0\n\ +Apr\0\n\ +May\0\n\ +Jun\0\n\ +Jul\0\n\ +Aug\0\n\ +Sep\0\n\ +Oct\0\n\ +Nov\0\n\ +Dec\0\n\ +January\0\n\ +February\0\n\ +March\0\n\ +April\0\n\ +May\0\n\ +June\0\n\ +July\0\n\ +August\0\n\ +September\0\n\ +October\0\n\ +November\0\n\ +December\0\n\ +AM\0\n\ +PM\0\n\ +a %b %e %T %Y\0\n\ +m/%d/%y\0\n\ +H:%M:%S\0\n\ +I:%M:%S %p\0\n\ +0\n\ +0\n\ +m/%d/%y\0\n\ +0123456789\0\n\ +a %b %e %T %Y\0\n\ +H:%M:%S"; + +static const char c_messages[] = "\ +^[yY]\0\ +^[nN]\0\ +yes\0\ +no"; + +static const char c_numeric[] = "\ +.\0\ +"; + +char *nl_langinfo(int item) { + if (item == CODESET) { + return "UTF-8"; + } else { + return 0; + } +} diff --git a/libc/unicode/langinfo.h b/libc/unicode/langinfo.h new file mode 100644 index 000000000..67d6ab62d --- /dev/null +++ b/libc/unicode/langinfo.h @@ -0,0 +1,86 @@ +#ifndef COSMOPOLITAN_LIBC_UNICODE_LANGINFO_H_ +#define COSMOPOLITAN_LIBC_UNICODE_LANGINFO_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +#define ABDAY_1 0x20000 +#define ABDAY_2 0x20001 +#define ABDAY_3 0x20002 +#define ABDAY_4 0x20003 +#define ABDAY_5 0x20004 +#define ABDAY_6 0x20005 +#define ABDAY_7 0x20006 + +#define DAY_1 0x20007 +#define DAY_2 0x20008 +#define DAY_3 0x20009 +#define DAY_4 0x2000A +#define DAY_5 0x2000B +#define DAY_6 0x2000C +#define DAY_7 0x2000D + +#define ABMON_1 0x2000E +#define ABMON_2 0x2000F +#define ABMON_3 0x20010 +#define ABMON_4 0x20011 +#define ABMON_5 0x20012 +#define ABMON_6 0x20013 +#define ABMON_7 0x20014 +#define ABMON_8 0x20015 +#define ABMON_9 0x20016 +#define ABMON_10 0x20017 +#define ABMON_11 0x20018 +#define ABMON_12 0x20019 + +#define MON_1 0x2001A +#define MON_2 0x2001B +#define MON_3 0x2001C +#define MON_4 0x2001D +#define MON_5 0x2001E +#define MON_6 0x2001F +#define MON_7 0x20020 +#define MON_8 0x20021 +#define MON_9 0x20022 +#define MON_10 0x20023 +#define MON_11 0x20024 +#define MON_12 0x20025 + +#define AM_STR 0x20026 +#define PM_STR 0x20027 + +#define D_T_FMT 0x20028 +#define D_FMT 0x20029 +#define T_FMT 0x2002A +#define T_FMT_AMPM 0x2002B + +#define ERA 0x2002C +#define ERA_D_FMT 0x2002E +#define ALT_DIGITS 0x2002F +#define ERA_D_T_FMT 0x20030 +#define ERA_T_FMT 0x20031 + +#define CODESET 14 + +#define CRNCYSTR 0x4000F + +#define RADIXCHAR 0x10000 +#define THOUSEP 0x10001 +#define YESEXPR 0x50000 +#define NOEXPR 0x50001 + +#define _NL_LOCALE_NAME(cat) (((cat) << 16) | 0xffff) + +#if defined(_GNU_SOURCE) +#define NL_LOCALE_NAME(cat) _NL_LOCALE_NAME(cat) +#endif + +#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) +#define YESSTR 0x50002 +#define NOSTR 0x50003 +#endif + +char *nl_langinfo(int); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_UNICODE_LANGINFO_H_ */ diff --git a/test/libc/str/blake2_test.c b/test/libc/str/blake2_test.c new file mode 100644 index 000000000..7e5dd42e0 --- /dev/null +++ b/test/libc/str/blake2_test.c @@ -0,0 +1,90 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/assert.h" +#include "libc/str/blake2.h" +#include "libc/str/str.h" +#include "libc/testlib/ezbench.h" +#include "libc/testlib/hyperion.h" +#include "libc/testlib/testlib.h" + +const signed char kHexToInt[256] = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x00 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x10 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x20 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, // 0x30 + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x40 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x50 + -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x60 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x70 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x80 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x90 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xa0 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xb0 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xc0 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xd0 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xe0 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0xf0 +}; + +uint8_t *EZBLAKE2B256(const char *s, size_t n) { + static uint8_t digest[BLAKE2B256_DIGEST_LENGTH]; + BLAKE2B256(s, n, digest); + return digest; +} + +uint8_t *HEXBLAKE2B256(const char *s) { + char *p; + int a, b; + size_t i, n; + static uint8_t digest[BLAKE2B256_DIGEST_LENGTH]; + n = strlen(s); + assert(!(n & 1)); + n /= 2; + p = malloc(n); + for (i = 0; i < n; ++i) { + a = kHexToInt[s[i * 2 + 0] & 255]; + b = kHexToInt[s[i * 2 + 1] & 255]; + assert(a != -1); + assert(b != -1); + p[i] = a << 4 | b; + } + BLAKE2B256(p, n, digest); + free(p); + return digest; +} + +TEST(BLAKE2B256Test, ABC) { + EXPECT_BINEQ( + "bddd813c634239723171ef3fee98579b94964e3bb1cb3e427262c8c068d52319", + EZBLAKE2B256("abc", 3)); + EXPECT_BINEQ( + "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8", + HEXBLAKE2B256("")); + EXPECT_BINEQ( + "03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314", + HEXBLAKE2B256("00")); + /* TODO(jart): do rest */ +} + +BENCH(blake2, bench) { + EZBENCH2("blake2b256 0", donothing, EZBLAKE2B256(0, 0)); + EZBENCH2("blake2b256 8", donothing, EZBLAKE2B256("helloooo", 8)); + EZBENCH2("blake2b256 22851", donothing, + EZBLAKE2B256(kHyperion, kHyperionSize)); +} diff --git a/test/libc/str/blake2b256_tests.txt b/test/libc/str/blake2b256_tests.txt new file mode 100644 index 000000000..8e52cf474 --- /dev/null +++ b/test/libc/str/blake2b256_tests.txt @@ -0,0 +1,820 @@ +# Copyright (c) 2021, Google Inc. +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY +# SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION +# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +# +# Generated by the following Go program. +# +# package main +# +# import ( +# "fmt" +# "golang.org/x/crypto/blake2b" +# ) +# +# func main() { +# var buf [256]byte +# for i := range buf { +# buf[i] = byte(i) +# } +# +# for i := 0; i < 256; i++ { +# h, err := blake2b.New256(nil) +# if err != nil { +# panic(err) +# } +# h.Write(buf[:i]) +# fmt.Printf("IN: %x\n", buf[:i]) +# fmt.Printf("HASH: %x\n", h.Sum(nil)) +# fmt.Printf("\n") +# } +# } + +IN: +HASH: 0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8 + +IN: 00 +HASH: 03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314 + +IN: 0001 +HASH: 01cf79da4945c370c68b265ef70641aaa65eaa8f5953e3900d97724c2c5aa095 + +IN: 000102 +HASH: 3d8c3d594928271f44aad7a04b177154806867bcf918e1549c0bc16f9da2b09b + +IN: 00010203 +HASH: e1eae5a8adae652ec9af9677346a9d60eced61e3a0a69bfacf518db31f86e36b + +IN: 0001020304 +HASH: 663694ac6520bdce7caab1cf3929ffe78cb2fea67a3dfc8559753a9f512a0c85 + +IN: 000102030405 +HASH: 274327d0e2a207844988fac0b39e071422e3f621913d69a5cfef23b38601a56f + +IN: 00010203040506 +HASH: 9df14b7248764a869197c35e392d2a6d6fdc5b79d597297920fd3f1491b442d2 + +IN: 0001020304050607 +HASH: 77065d25b622a8251094d869edf6b4e9ba0708a8db1f239cb68e4eeb45851621 + +IN: 000102030405060708 +HASH: 8660231b62ce1d61fc8be93bd6acdb43ff61a7ab4cc9494f0cc803362360b07b + +IN: 00010203040506070809 +HASH: 8b57a796a5d07cb04cc1614dfc2acb3f73edc712d7f433619ca3bbe66bb15f49 + +IN: 000102030405060708090a +HASH: cc932bee351be391849c87925f2e00a83051419dc310b288d4304d4adea3d0e0 + +IN: 000102030405060708090a0b +HASH: 99bd72c73bea193f7040ac279bd656cdec7fd35e097a657b6c03b4fa967223ed + +IN: 000102030405060708090a0b0c +HASH: 695e93b723e0a08e8dd8dd4656389363519564daf4cde5fe95a6a0ca71d3705e + +IN: 000102030405060708090a0b0c0d +HASH: 4cce7128e4f659ba41ee163c45280d468163adc8c76c4937a0bbfa0cf3bdeae7 + +IN: 000102030405060708090a0b0c0d0e +HASH: 929cec40e9e746e771c6ad05cfcf37641254ef5e802fa71a02f8982f525f2b00 + +IN: 000102030405060708090a0b0c0d0e0f +HASH: c7cb5d1a1a214f1d833a21fe6c7b2420e417c2f220784cbe90072975131bc367 + +IN: 000102030405060708090a0b0c0d0e0f10 +HASH: ced0cd609f3c8ff85b9cec93bba556dbe3caa996ac5beb629d4512473d6b31ae + +IN: 000102030405060708090a0b0c0d0e0f1011 +HASH: 584c9cb4da3be635d86e803c9eebccfd27fbed4aae27b0207ce3c934a0043aa4 + +IN: 000102030405060708090a0b0c0d0e0f101112 +HASH: 9b508680d1f75d5f1e5306fbfaf7e88621cebf39f7f5cbf9e2dbb7ebb88504d4 + +IN: 000102030405060708090a0b0c0d0e0f10111213 +HASH: 5d597f201ead11daa0687185c579efd702e288d5bd72b6b21238a4ecb52d288a + +IN: 000102030405060708090a0b0c0d0e0f1011121314 +HASH: 85b8afd95165d04681ab948f2f0545c47a8d11d9d1866cb7ecc88bc31a634891 + +IN: 000102030405060708090a0b0c0d0e0f101112131415 +HASH: 93c541c87fb52d506b1b262e49ed71689a15b745e8f3e003893c8c59cfc669fe + +IN: 000102030405060708090a0b0c0d0e0f10111213141516 +HASH: 395d6a5e3b41b6151411b9b22f07fcbae6c7c30df59c10ca2dfcfe333ac8e3fb + +IN: 000102030405060708090a0b0c0d0e0f1011121314151617 +HASH: 8d71aeb3137041d31ed42466ea5fdca2ec7a35c7701d142ccb813f8c614ceca2 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718 +HASH: 3b0b9b4027203daeb62f4ff868ac6cdd78a5cbbf7664725421a613794702f4f4 + +IN: 000102030405060708090a0b0c0d0e0f10111213141516171819 +HASH: 7384c8812f6803d8649bed21a3acbbf36239bbd17274d249369dd65e6329fd84 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a +HASH: 3890962f7d604fe0fcade7d8fc03c7e6285da2035bac5a9362c1d68a353d5350 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b +HASH: 9dc0b41d6a6a6c194d04336eb383ac7f4ea537700d5926346dfb1379e9453460 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c +HASH: bd78e1c368d70b968e194dca2c6fbda605a67d5e52824289e058c93eee073ef5 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d +HASH: 4cc3e428d63dc132471d3135d406f8d6e30d2480d571bffbd64957bbb090f582 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e +HASH: 9adf65b53153b1caec84cd717e00e01c2000d0569704ce38d065180adee5d964 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f +HASH: cb2f5160fc1f7e05a55ef49d340b48da2e5a78099d53393351cd579dd42503d6 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20 +HASH: b7634fe13c7aca3914ee896e22cfabc9da5b4f13e72a2ccbecb6d44bbda95bcc + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021 +HASH: 9badddebf24552cb1f66d32990476594e5249a729254f7b5c840728a42749a45 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122 +HASH: 13891b823d3a2cfe0d1a5e60fe89d8c091524f994cdc3241c4da19c4bb3c2c6b + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20212223 +HASH: c1b7eb8d130d705c5fa9ee8061076a3151f2e36e42d9c9289d85065b9ab343dd + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021222324 +HASH: ee6a288c4fcae34572fc6dba3e0b7d698bef65dcc63bf28ebd74207a2065718a + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425 +HASH: 1b5ad5f31e4061f423ee11e3de88fef05dfed9393c268fd360d05fe4465fe40a + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20212223242526 +HASH: 87c40636d0ee94687fdf020e3d165f4e45f21d62fa04aa2b9103a8187da6e64a + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f2021222324252627 +HASH: 70a3082dfc7582b9d252939a474338db1f94a6dcc7724709377797d17ff51ac5 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728 +HASH: 109036d1dece657ac6471f7f7ed33846986fdcb9dae8a73ea0881607e5e45f13 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20212223242526272829 +HASH: deda4f3e98e58392adaee3c2e7b91d172551c50945a8ae9e9e1ad10c2ae510a8 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a +HASH: 2a82cabbbb09956d212d182cfaf7cde2f55fa33f96e3a1ab19fccfdb668ce2f2 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b +HASH: 4a21b38c69f755c016ebb4a66eb76b4f9d4087a02fc8c3c257c1183efebda824 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c +HASH: d3ecaa4853a092755c3692cac3fea5d9ccfaca2d32b59ccae151705333359e79 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d +HASH: 0ab5250248686afe6eca3f3ed89e061c0b3ae2a13454b907bbdb643a72b25a66 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e +HASH: 2fb57ab5fc0927e8301b6933325530e90fa7a94eaea95bad7c3f2f1052032900 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f +HASH: 48de881e6c1dc35253d9c8d56e773743640f097bb7274b80ec090f1b33d1dc2e + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30 +HASH: 71745158a70425e25a8446122dda82fcfeb6bfcb593b25d79c539c6b989c526d + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031 +HASH: 45d3d95f04f304be5a61ef38357bd01e61f9bb7f8c9979458d846d9899436167 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132 +HASH: d5afebad633b7d595e6c8482d8c9a429091f58acbd84725adbac12e8be80ada9 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30313233 +HASH: 06bbb3b17ea95e7e00ac21b8632f84615f11456fabcda9d99cbf079e3134cfe5 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334 +HASH: 02b8e881b5f78b451995f07116af3549066cbce498497f546a9772981779d908 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435 +HASH: 370c5efe99822c30460a123467e8f151f012065ba3639bc0407ed3b3609e5d56 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30313233343536 +HASH: ace7db9e8f298e823b7b265bbcd004577e0029256c48684b2d7a7cdfcbff5e47 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f3031323334353637 +HASH: a6c1d35f74218e57b4dbd4ed467b41981208666738ffa0d9dc53d3de96be702a + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738 +HASH: 25e44457f063ae4ea799502c38d66eeefb46f520b4fc9a298df9826c9d62eea9 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f30313233343536373839 +HASH: 1b35b64cf659d6d7d0ca933c9a52fb0e67fba76a304fadb7c47dd8ff6b6ff0fa + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a +HASH: a72de68ff63bbe9ccfaccfa6859af660bb413f9e5d0200106100919c10301ef8 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b +HASH: cfe37ab9c02bf84afa7a734a10317150479b791a27efc374dd669f4ef67a801d + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c +HASH: a55a2c06f3db74c95b33d1e962da18772c3601eb13fe0b86a78667b2b9f9df86 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d +HASH: 1b8a9195724ac01ad7da4a76c2545d2f3dc223a0242537050d7395f588748079 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e +HASH: 29e41a64fbdd2fd27612228623c0702222bf367451e7324287f181cb3dcf7237 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f +HASH: 10d8e6d534b00939843fe9dcc4dae48cdf008f6b8b2b82b156f5404d874887f5 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f40 +HASH: 84c04ab082c8ae24206561f77397704b627892089a05887a2a1996472bcfe15d + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f4041 +HASH: 2b684baba4a7245e38c3263d85b5524a51baa8ca18444af1b5958596bc30d424 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142 +HASH: 1d59fa9501213440975a0b27e4b52eea7274f8794ec35b8ee4824f7b00897ed7 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f40414243 +HASH: 60669608711b9df3715b631b474d5206179a81d054ef5494612899728b55e103 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f4041424344 +HASH: 46060cb9dc6be177bafe5425c4f84f9143b71cfc75dd958e15ff7a26cc92859b + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445 +HASH: e7f909c8e018bc36b59a8e7848d16c05d6bdb0ebb91fb9baf54cc328192cc362 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f40414243444546 +HASH: 7a9f75439c68869a6595eb63c61db2bc213d3ef067ec0cb3f25e02e554fce2a9 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f4041424344454647 +HASH: adb39b3e53a791dfd32eca83191eb82fdef4321ac504539b257c3376da240aca + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748 +HASH: 240ca19b3671dcc5ef174331fb0dd24b845dfcd01b0fbe52fa72a29bcaef1373 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f40414243444546474849 +HASH: ebae0805fd52d3e9f5f29aeb33b6be8cab0f28e668990d3cb95444d9ef90b932 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a +HASH: ea7c3c052928f0fa3b8d86b19c87dee905e8a4b26a0a23b3c8e8dc7255ea82d6 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b +HASH: 4ad32c1f2d18c8b7dc29d1526d7c751b89b86882fb12aa3cc9c6eddb7991d266 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c +HASH: c61f81c3e6b899d0501b05df1de32099a7b0e878689dc2a3fd5583de90a74164 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d +HASH: 068a8a0b96076a2773a8e00e00e57eef4fb26886b521285a6c747130850792d7 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e +HASH: efab0151162523b18147cba89679bdab2d9b670f5ae222a34c360c094af1d441 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f +HASH: 066de1009daca2b8390a9dc734bce547ac4e3cc4531645bb8b9cbc0070941d88 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f50 +HASH: 9fbb33b95e79c5c1683ab09a6abff6612fffb4458543dc8bbc7723a6dc2bf2ed + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f5051 +HASH: 88fea89237618cfc0270cbcd08e7ffdaa8933607c0dbccb8dd075b84fba83b11 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152 +HASH: b1960beaa4fed01453679c7d6cf78d25442bdf92ae51be479dab18e1b2b922d3 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f50515253 +HASH: a7d6821a97bc57cf6b5e25953c689439beda79364c903a3e64b6671dc9eceb2f + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f5051525354 +HASH: 90ca93ecd3e0e7c839e4fc0f2e4748954a89b2c7338e55fc18a53ccd08abed2e + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455 +HASH: 58fe5f45b9915a5b177f4256b51ce5781662352a2dd620a946b8755213fbd61f + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f50515253545556 +HASH: d109c8ec77e2253b5e7c761f59b184815e46b06cc5132a92511a93dead6315c2 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f5051525354555657 +HASH: fd9664ecb814785c8474188706e6ab0952925f9b9d8e351665ced12e84d92fad + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758 +HASH: 81342700c48f41ec5b54180d560e73e5ad6782717b2d3320b42280be11f0873e + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f50515253545556575859 +HASH: 523cf9a356076fe8c3538bdd752bc43712c7d28f29499aaae7812f1e4167840e + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a +HASH: 9706d70e28a9e99db15974b1c01635868a62c6567eb40903adae58d417b882f2 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b +HASH: 2216f01255ff24422e18d906c64506924940451e09d4ec17e4dbc8ea6d14ef59 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c +HASH: 64ad22e77fc9f8a03ad6e06a067add9f0e0360d4533014fa286ccdf40dceb231 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d +HASH: 9908418a2bb564ab9607d2f863b841dd4fe47ee370dde05a9368e400f7f9904b + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e +HASH: 981a7989084e74f6d5fd8870321e860991729eed88e60d85ab5fdaa769be6fd2 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f +HASH: 6528ea458efd23391e968e0dd3a40202ac94e3854d1a4642cbbe0d13a15cb849 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f60 +HASH: 767fdcd43cf16cbf980fd560dfc55f67be20510f9a0c8fcd5c749da8ef23fd7b + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f6061 +HASH: 90afc4e366bcee748591d93ba9f7c2e05a1fda261b58d094f8f0450c8a31ffb8 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162 +HASH: 660f9f5d430bf89f5946fd4649ad41f806937641c808a80da70660f53179a941 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f60616263 +HASH: 5ac86383dec1db602fdbc2c978c3fe1bf4328fea1e1b495b68be2c3b67ba033b + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f6061626364 +HASH: 7c15cdf3705457eb6b8edd79fb75bf568692ccb778f85fa2e1d462f48ee55c4f + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465 +HASH: a8df989766fc245edbb4b7268afb7380e4ea3f7123802b72ae2adb938211c9f9 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f60616263646566 +HASH: 707aa875c6162027ac2829894c0be750f5ee8fe8a64465080025f708dc200f0e + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f6061626364656667 +HASH: 6efd41538fec50459b6c2583ade5754c86617580eef3071d38723aaf743f93c7 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768 +HASH: 5c22d6a56a4fbdb85aa70994b4e118224bb6db2afd017a98c2b992ce26ea8925 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f60616263646566676869 +HASH: a4a9739a1c83135bab3334990b470164ed81f633d7fe79722b3ac6e65dadd38e + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a +HASH: f1ac1ad3348ea6c949fde09cbee706ea0aecf3a93fc51a8a7e2bdb8cd7400b01 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b +HASH: 492d9eae92f27ecce118d3fd8df63158cf709ed5069502263b8be1c105196ea3 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c +HASH: 8691c32810f3220c0df76816af0a73b3fade2594cbcc711b855e2cd81dbdec95 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d +HASH: cab341f7059d974cbc620bc423b02f58b5e1a899f416b0858ae1a736d4681162 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e +HASH: e08b3d16f0a3b663f319da999db897488d1677048a38fa7b4f1f783e4f1974e6 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f +HASH: d5587e0b33166a320dd69417adb01cb1129aff5506a2f655574cf2e264636bdb + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f70 +HASH: 5a69194c22af2b7040a8488738f96c901ae215965d611a572932464261539fc8 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f7071 +HASH: d8e7d58cd37acad505940843a8bb046971c43e4d0593c6bb946b07926644f78f + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172 +HASH: 46b07cc026b633e6245661813d5aca2bcc295d0b8ab01f27f517b4f2823d0b3e + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f70717273 +HASH: fc169b3e5480e72057d828702f9da4f08d141a178eb8adef03ca0708c1a10df7 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f7071727374 +HASH: ae3e241c1c394190fbac7fccb3df0d0bc317c6e1a15993330e9b648c80264066 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475 +HASH: f430aeef864823d8c8b448f2d25452ea3ed7abe2966adc8c42636b69d0a1bad9 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f70717273747576 +HASH: b0d6518afa4e3590746aa5fd1e58f7ec06a347981177737ad6631b22c53b6617 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f7071727374757677 +HASH: 16684ddd272dfc18dd40c16a7f57cecca70df0a96c4a066b97646953e7c7691a + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778 +HASH: e8208de0982f3d8e9ac258eb26eb3f130ced7331797b625d6b65ba4ba2064c9c + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f70717273747576777879 +HASH: 8ecd4bdc226fb29dd486cd77b566723e44c77194ba7a000734736dbb76f61c7c + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a +HASH: 153d5c1d5edb08f51f6353b6b7bdd48a9bba14068923b8991be59346a4f932f7 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b +HASH: 60e555a694396b48273d2d778709c208c0757cd15697a43cf0c2115599c80e68 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c +HASH: 7a4a15b47029005972a6b814d5e7f2c86c616bd98e6a06bd95cbed2f47400c67 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d +HASH: 3de5adb8e3bf8dfabb41afe53c58fad23427a148755148011b5c12b88aba3dc0 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e +HASH: f2fe67ff342e21b8f45e8f2e0bcd1d9243245d50ee6c78042e9c491388791c72 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f +HASH: c3582f71ebb2be66fa5dd750f80baae97554f3b015663c8be377cfcb2488c1d1 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f80 +HASH: f7f3c46ba2564ff4c4c162da1f5b605f9f1c4aa6a20652a9f9a337c1a2f5b9c9 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f8081 +HASH: d3b11b4cbe513ec7b6f4bb5ff0c411de405a8641cf221493447a35927ca3aea7 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182 +HASH: 62323574c7cdaaca448fcbc7091ae4af3e04decb0d3c7c55636baa0a99c88699 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f80818283 +HASH: 89b7d0203387e0332622ca84a879bddbcff155a213997560fc05428e79e06891 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f8081828384 +HASH: be5cce3e365fbbb139f68a3da3367e42aa8bd79b15f5252f7c08c3c8f0dcab27 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485 +HASH: 7ae7702bc025692f2ea5ab0c2eb6552c7975a57c5acb93ff115d303f341a579c + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f80818283848586 +HASH: f7c4efacc0a4cb5836f170ea0bf5dc5ce36fe2d88e76a9f259eaab71aef0ff13 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f8081828384858687 +HASH: 6a35d3dadc62dfe7819519f92181b2f8d38f5e0ed3d51a22cf8a133ab628d6f4 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788 +HASH: bacecc2948c41beb73c815ca7cee6c7dbf2e4219190936edac5e4680500dd4d2 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f80818283848586878889 +HASH: 2dce89f76f4f37472ae6374b0825a9cd61619a995c7f49733f62b606a7ce905a + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a +HASH: 7b65e63a0d17d68c798b5d5631f17c35faff70dbe90006589ca89277dbeeafc0 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b +HASH: 9477e374453099d2f8679e1d9b167b5f1c4e3cc66f32bdd9a3748a10876a27b3 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c +HASH: 448437adad41878e6529fcc2fad9bbdb13697b6cbb2669fc8150d3aa7e0418b8 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d +HASH: ce4936743020825f508ca72c8355c88224a52c348a21567e65526ff8f82632fd + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e +HASH: 556a195bf23cba5c3193fbbe472f1cd5478ea4cad2dc6d6a193102a2abd0fac4 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f +HASH: e15dc6238e2e58e9ea212b0d7abfd700da3ae5120d4d601341ce9e424a7c5828 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f90 +HASH: a22022450276c5018d51cd321e0e195a0add003e33ecaa97028d6974b5712187 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f9091 +HASH: 044cabb79e57da22b772249c332bfb43c5d1c9b683d1b2d2b75f4c5e6773a216 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192 +HASH: 766e1167593896bdc8793fb7ccdb1d35dc430aaeafe1e7a96aba870416587e7e + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f90919293 +HASH: e19d72ca8438477db71e1bfa48924c4e75ee4f84c7aa9b0911521c60a2ba6440 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f9091929394 +HASH: 512ee7aa89497a761f0798c29a1dd37d1d86f1c0870519a0aab69d265df118c0 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495 +HASH: 80c199310a2ab7af6a808f6d68843136c30e9228a766618632d4e1210edf365c + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f90919293949596 +HASH: 43fdffd19c692b6ef87c103cad9b80fb86919e6ecdcb73364d260da29a5f28d3 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f9091929394959697 +HASH: 1d1dc1909a6a8e552a0f8964601102d0edc89f5a02d3acced71826bbc5ca37af + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798 +HASH: fa77dac317e8c531246e14265ed42a87ade6fc3ce351652e6ad9290f8a157617 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f90919293949596979899 +HASH: 5bbc0f8b1a52732ed548e600865ae53360f0642a5674ecc7c6185f2cdeeb6601 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a +HASH: 89c5fcbaf3a61d6fa4fa33c3eca8761ebab3c3467aba7d255394a0e70811ef3f + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b +HASH: 9b3ecec85fa5ba5e0f1542085fff46bb2262163979879c9565294b2c56842a28 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c +HASH: 4e301b852d473b5d12271209bdc350b4ec615c99cb07bdc2b379f86679b465bb + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d +HASH: b306fbbb65eedbd07aea67a6490db9158a768d8223772d9414b124fe184098ba + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e +HASH: de9fc91112ba62a5b732d4b708d6cc27a4b77d88e8f9c50db361c6f27295b46c + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f +HASH: f3aac26dc5197ea8dc068d6bfc9e3ee2217d908df5115fd236ba31828637ab7a + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0 +HASH: 3a0126ec4db7bd8c0c44e5197a84465c9c97c45f9d1fb8ab256eb5681dc25000 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1 +HASH: 7b6b55e2623a8eb6d70fa0913012e3db03cea4a6ddc0f5b875673a225f95d86e + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2 +HASH: be3ed738f221b53726d8a54ab7171189d77700bca86a2c614f5fefbca37eb5b0 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3 +HASH: c90bcb90aea0ab6a2331ecc17f4e68507b544910f3561d20a41916d8abb421db + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4 +HASH: 72f18a50776c9efbbb1d360342235bf28ab259648dbc08480390333314e02672 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5 +HASH: 2f1c635728444b5189540cf99d92a77057aed5a8c6fd7deadbbf9d86815cf5f9 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6 +HASH: c372e87d3540fb30e7316af85b65378384de4664a04e51b30ada778e3a226d85 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7 +HASH: d244f4ce129ef1c84eb40d30da099a2d65682e025e132b94f630fa3fdbda05af + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8 +HASH: 930a3e1f69ef7bcf3b9a81c1feb9758f60f9086b331fc170e6fa20b2a5738540 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9 +HASH: 84c3e0415a9d4da972a4fd9ee82d63b00099a2620889bc274ecb8606912cf92f + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aa +HASH: 6d0d4cde9886218e9240a0c956836ea3939b558b8da0b309ca686f3c631f4942 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaab +HASH: 86e476f2f8bacabc996360a0d6d57f0e045c9d3085ffe06d2305601c30d2340c + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabac +HASH: 6ca5fcf07d2d4b1449924c8c84ad2c2e432a1f923dd365d81d9fde3c4985724f + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacad +HASH: 9a7e1a3b1e01f24fce4d115eb98e2bb9eef349cf0d40493b8ab33727c9a1ccc8 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadae +HASH: 165509739c09ec3486143b0c7c009d5b588736aff2813a2dbbfd733d5840ef98 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeaf +HASH: ad191a623337f01563824b493bd735bee26833e9224d971a67b453d6e113d96a + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0 +HASH: f99e6d680bcbc6bb384290a5f966b18d4db38951abe695c6444c319058bb8904 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1 +HASH: 20e7e81e12c9ad28b7d65d3917051c327031f334a2f82b1f746cbcd7dc41f87d + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2 +HASH: 14675c8fe5cbe514491f7093aad58e9dcf8dd33ab22f3a8bca1ca5130d5e5bea + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3 +HASH: e105be1caf056cf599b91423df3cc1fb2808e0c6a50da68fc9db5693d1e0a9dc + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4 +HASH: 8fcade674361487f88d58330acb439a4b3e717341615ba691370becf4905e057 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5 +HASH: 70251dcdf7c899bddd4bc745597b998506c34bebc5de115d4fe85af2aa420171 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6 +HASH: d987826931a47b9ff871a0f2a8f10bbb659598da57d8abf81714b48a475a1356 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7 +HASH: fea31b338415f503dcb3708d68f377c4267e96345158e7b88d24ec8c232ef2b7 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8 +HASH: 3f2084debfeafa75d0c078bed7eda160459a3792a440c3718fb5c14c118e3263 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9 +HASH: e55583bd588fb053f040c541db36603e4959a7421d6281fca88454720da34c17 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9ba +HASH: 0f433de1bbca62440be5d1ceaec8138a2154b374921d17e2d6493f85529a5ee2 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babb +HASH: 39cc27d72466d2d63f70f28c59950a0665005b4bc8cfaaa662aeeaf34a19601f + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbc +HASH: e7a556efdac11394b6058496b06dad0eb7315cae4cbd509e77e496c85f202aa4 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbd +HASH: b90cf1fd5dbee8a9c18764962bff431dc560e113073828d839e11929d7d602ff + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbe +HASH: 62b227effe8222299e757a065f1b64ab73fe6d2aac5d762303db956bc82b78ce + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebf +HASH: 7b8f54247422c43a6d36977260e195d06e1dbba44c392b3fe76dcf4a96c433d5 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0 +HASH: d1400c9e8c7758b19e29c38e356ebc7abe8c0887741b845426821c7f74ebd35e + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1 +HASH: 9c557316ebd1e9cde622271e48f654553067c08d58986190bd3108d8bf54f130 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2 +HASH: f005478fb35b7a389377b35fb6193aab0e9f3c4138127d0905e488a3e5ed1bd6 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3 +HASH: f62114d69c3bfa8493061f44df01566e3a932e83b050b94eca7a1f7f189d6471 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4 +HASH: fd915ae6a50c06ba3917bb6d001a4b84c2ff8a906813ba78e80b043a91e7d1d6 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5 +HASH: 2176a39525e6a57ceed2f28eda5179172ec4f5a15be41b6cece8ab140ff1194c + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6 +HASH: bb831d2653af40b4e8a1048309c1f058d21334aa20c78dc63b8eb74a56fbde3c + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7 +HASH: 63c3d97a9f8894d5e043a707b0fee7f7ec4c049a23bbf1079df20b4165f9e22d + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8 +HASH: 3e53214e700694863284e7dc8dec3b98c1eaf97add0c1431e3bd321d6742a586 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9 +HASH: cb4e69b8adacdcb20dd2d79655117de489030ecc86c210a268b9985126ca9df3 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9ca +HASH: 33eb4a42f46198eb7b52f8fd556fee08430872d3ad16fc3fca466a2d63cc4932 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacb +HASH: 4fb1c07cd6e6ed8dbfac72210f3ff9707293dad1f8a4aa19f0ac8ff6c80f3ce9 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcc +HASH: 22349aa35acbcffa6c84ab0e0231199d8353adde248ca1ff91010234886c94de + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccd +HASH: 4ddf8cb3d4e80c9971a9ab171f9bc29fa4fd23eceed01e3bc297892de389d6f7 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdce +HASH: 69be23136e4af5f52bb333deb3f32f76610b9fd9dac9ede75b2ef0491bf218ab + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecf +HASH: 0b5ce2869ebbbc91bcc4d2e9560bcc21f4da20fffc96cd4eec422b795641c808 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0 +HASH: 82c17ce6066f792df2dce06eacd03ab4d202185a0a531e4af9a1a2d7b2d43def + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1 +HASH: 97b1b2e7e7aa6a9d1821ee2ad6c8062af397072eb9a8547c75817d0f0ad1659e + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2 +HASH: 5aa4d29af9903050d5d329d4d7f3a657ccd038543da764ed931560f799690a50 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3 +HASH: c78b17ff5ea603a809668bc06dbd99b78561b37ff615f6f5e5b86165a442ec2c + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4 +HASH: 2d1f5fb13901a205b158c5dc01bf54a5bfa9914c6b19ab66f501da64975e3a4d + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5 +HASH: ef7d3f61c537cac2a217cc214cd9d3e80f4adaac8431768f9db88a6571d3a57d + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6 +HASH: b23a6eb1184e297b5e9ec2e3aeeaec3c8de411dc614f2979de285ce4d3802e18 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7 +HASH: 6598f5924005cd92e779a5525636fb061a1cfe4e7afe97d468eb3106817d6c7a + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8 +HASH: f0aec1c2872dff14f3592c5f7e83c0dc4d299f94a7cfb247d0a4b95b9b0fc077 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9 +HASH: 709da24c1ca042c055a3cff57280d72f2b50094bbf029d9aed1dcca3288022c8 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9da +HASH: afb0abb463999cc9ab124c95993d62e839bf7409d91d1c377912a895523c3125 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadb +HASH: 049eb53d4bc939e817c9572a5f0def95e4e38b4614969d866e738e3ae6e24936 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdc +HASH: 1f9df26fb5219482437297326737c0558eb557da4eb6374805dd9a30f842aae4 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdd +HASH: 11151481e2199be550f9ae696cbd9ddc9be9686dbc77b619c005d0fb5aef9b89 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcddde +HASH: 0767c2de1353f58b416e3fa492173c9c39792de46a34c6153d5878ba01e5f07d + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedf +HASH: 46d743927ec8ad5e403c9e20405200481961e7335e90c4ea9c5ad35b77f3681c + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0 +HASH: d5ffd30325257614674de0b40f7b2ded3a287f48ae229b02c91dd2be28404171 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1 +HASH: c36f10f2463b839f4bbe7130c8f3abf29a56608bdf767199faccadecc8245631 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2 +HASH: 4265605e9d5b02fc438c15823bdd01cbcec073d57ad7a699d0126312fdbe4322 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3 +HASH: 829f989b205831d3c5c002ebf8cea1b5fba3daf966539e3b421b6c2c768f7554 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4 +HASH: 406a227d2d1767e0cf417d6bf7ca58a262c79460f421b9c155513714187d10d2 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5 +HASH: adf7d0028e41121e47aef77dca9de82fef7fe4f4c82f2d6df253adb4e756f2ec + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6 +HASH: b9a11305f92002de551314de53739b1c7e31c257149aee21f3a5ba4af068215d + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7 +HASH: 49f9abbe9007e85091827b49256730f552e4a2170a7b6f9cc461483bd8ae0d52 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8 +HASH: 98ebce2d0b548d9fb99fbd63d842c119f2ce671317cd080ee036fa69457fccda + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9 +HASH: 779042d9184c626289868dc73662e71f413c1df4fecd2f08b0edf40bd8d520f4 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9ea +HASH: f8ad01320e4bbab09282a97511598384089a447f9a6a8fa298b65a82f1731806 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaeb +HASH: 1d799e024fd1627cc0395c68bec456631153bffaeb625cda58411b9cbe137b34 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebec +HASH: a9ba7072400dac24052ef744ca60c8273d743af357c851a7016cafd599225672 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebeced +HASH: b02147bf83730cc51219f660fe93c63a7463c765395b6721bb842e3ef230e6f5 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedee +HASH: b642374d57afa89053dcb7f6e1e72680fb96e3f28adaaf5aed89ab4cfc78214a + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeef +HASH: 546b4be370ba614a1761fe8cef8c023d6a7f968981e23a1e8e1168b25cce2efa + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0 +HASH: 72dab9724f6e174d48e6b8caf489747995d649828a1b1d7a6e8527d9a01523a4 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1 +HASH: 30b611734127b847bed5c68a867bcded79b2b9da0a358dbe15c4dd578f81e6c0 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2 +HASH: 986317b1d1afd4692dd533a712718196d412f46a6f3166f417ef01306ab695dd + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3 +HASH: db6329f783adf7cf5a10e47369fe03c95bcf523558f3aedf18b51a355a252517 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4 +HASH: 54bb60a43c1e045644420916bac42cc72f86649fe8efeec866cd8e8128a88def + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5 +HASH: 802875948f79eefb707094e323a0faa2d6d88949a08c044ed3757174492bd2eb + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6 +HASH: ffc9e261842e1afdaed9f364f125301f20ac8fb0eea556db975211c7db281daa + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7 +HASH: edfe0aa71067c62e894a516a72dd4bef8c3917e46eb22d39626ea826b90804e9 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8 +HASH: 98832102b93bab4f82ee872d1dc96d2651ccc9e908c3cf25a56b59cce20319df + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9 +HASH: 1248d2d1736f1c125c6928bf893f581ea25be6e6e3d3c46081c557de591d6c6c + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fa +HASH: 7a01651d8ffa44f6695270c73066ca9d61733ae3c181e3477d11e7c9563594a3 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafb +HASH: ced595397cfd128aadbf451002457ff5b0fc2ac3993cabd47f0fc3ddbc6d0f32 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfc +HASH: 8797db8dd8ddd1ecbee1f1d71aed5d41adca8345277a7bc0b12df75bb4536722 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfd +HASH: 369b09e04be27275df75c180d7283c083162f35456152f0b16ae680dda5195bc + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfe +HASH: 1d0850ee9bca0abc9601e9deabe1418fedec2fb6ac4150bd5302d2430f9be943 + + +# Longer test vectors + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfe +HASH: 450eee5f3502c7d5ac7f223d4b4f2c76a11e5bd02d253a37ca9e6e901d5fb56e + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff +HASH: 6ed9bf545705dba5971e83a1f2a46a9dd5ac2fe8a934f13cee8d353003eaf908 + +IN: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff00 +HASH: a43b19ed8f147f18c304bffeec559e63e83877507cac11924edaf9eb6b6c1bac diff --git a/test/libc/str/test.mk b/test/libc/str/test.mk index 692918214..50971c904 100644 --- a/test/libc/str/test.mk +++ b/test/libc/str/test.mk @@ -6,73 +6,83 @@ PKGS += TEST_LIBC_STR TEST_LIBC_STR_SRCS := $(wildcard test/libc/str/*.c) TEST_LIBC_STR_SRCS_TEST = $(filter %_test.c,$(TEST_LIBC_STR_SRCS)) -TEST_LIBC_STR_OBJS = \ +TEST_LIBC_STR_OBJS = \ $(TEST_LIBC_STR_SRCS:%.c=o/$(MODE)/%.o) -TEST_LIBC_STR_COMS = \ +TEST_LIBC_STR_COMS = \ $(TEST_LIBC_STR_SRCS:%.c=o/$(MODE)/%.com) -TEST_LIBC_STR_BINS = \ - $(TEST_LIBC_STR_COMS) \ +TEST_LIBC_STR_BINS = \ + $(TEST_LIBC_STR_COMS) \ $(TEST_LIBC_STR_COMS:%=%.dbg) -TEST_LIBC_STR_TESTS = \ +TEST_LIBC_STR_TESTS = \ $(TEST_LIBC_STR_SRCS_TEST:%.c=o/$(MODE)/%.com.ok) -TEST_LIBC_STR_CHECKS = \ +TEST_LIBC_STR_CHECKS = \ $(TEST_LIBC_STR_SRCS_TEST:%.c=o/$(MODE)/%.com.runs) -TEST_LIBC_STR_DIRECTDEPS = \ - LIBC_ALG \ - LIBC_CALLS \ - LIBC_FMT \ - LIBC_INTRIN \ - LIBC_LOG \ - LIBC_MEM \ - LIBC_NEXGEN32E \ - LIBC_RAND \ - LIBC_RUNTIME \ - LIBC_STDIO \ - LIBC_STR \ - LIBC_STUBS \ - LIBC_SYSV \ - LIBC_TESTLIB \ - LIBC_UNICODE \ - LIBC_X \ - LIBC_ZIPOS \ - THIRD_PARTY_MBEDTLS \ - THIRD_PARTY_REGEX \ +TEST_LIBC_STR_DIRECTDEPS = \ + LIBC_ALG \ + LIBC_CALLS \ + LIBC_FMT \ + LIBC_INTRIN \ + LIBC_LOG \ + LIBC_MEM \ + LIBC_NEXGEN32E \ + LIBC_RAND \ + LIBC_RUNTIME \ + LIBC_STDIO \ + LIBC_STR \ + LIBC_STUBS \ + LIBC_SYSV \ + LIBC_TESTLIB \ + LIBC_UNICODE \ + LIBC_X \ + LIBC_ZIPOS \ + THIRD_PARTY_MBEDTLS \ + THIRD_PARTY_REGEX \ THIRD_PARTY_ZLIB -TEST_LIBC_STR_DEPS := \ +TEST_LIBC_STR_DEPS := \ $(call uniq,$(foreach x,$(TEST_LIBC_STR_DIRECTDEPS),$($(x)))) -o/$(MODE)/test/libc/str/str.pkg: \ - $(TEST_LIBC_STR_OBJS) \ +o/$(MODE)/test/libc/str/str.pkg: \ + $(TEST_LIBC_STR_OBJS) \ $(foreach x,$(TEST_LIBC_STR_DIRECTDEPS),$($(x)_A).pkg) -o/$(MODE)/test/libc/str/tpenc_test.o: \ - OVERRIDE_CFLAGS += \ +o/$(MODE)/test/libc/str/tpenc_test.o: \ + OVERRIDE_CFLAGS += \ $(TRADITIONAL) -o/$(MODE)/test/libc/str/%.com.dbg: \ - $(TEST_LIBC_STR_DEPS) \ - o/$(MODE)/test/libc/str/%.o \ - o/$(MODE)/test/libc/str/str.pkg \ - $(LIBC_TESTMAIN) \ - $(CRT) \ +o/$(MODE)/test/libc/str/%.com.dbg: \ + $(TEST_LIBC_STR_DEPS) \ + o/$(MODE)/test/libc/str/%.o \ + o/$(MODE)/test/libc/str/str.pkg \ + $(LIBC_TESTMAIN) \ + $(CRT) \ $(APE) @$(APELINK) -$(TEST_LIBC_STR_OBJS): \ - DEFAULT_CCFLAGS += \ +o/$(MODE)/test/libc/str/blake2.com.dbg: \ + $(TEST_LIBC_STR_DEPS) \ + o/$(MODE)/test/libc/str/blake2.o \ + o/$(MODE)/test/libc/str/blake2b256_tests.txt.zip.o \ + o/$(MODE)/test/libc/str/str.pkg \ + $(LIBC_TESTMAIN) \ + $(CRT) \ + $(APE) + @$(APELINK) + +$(TEST_LIBC_STR_OBJS): \ + DEFAULT_CCFLAGS += \ -fno-builtin -o/$(MODE)/test/libc/str/memmove_test.o: \ - OVERRIDE_CFLAGS += \ +o/$(MODE)/test/libc/str/memmove_test.o: \ + OVERRIDE_CFLAGS += \ -O2 -D_FORTIFY_SOURCE=2 .PHONY: o/$(MODE)/test/libc/str -o/$(MODE)/test/libc/str: \ - $(TEST_LIBC_STR_BINS) \ +o/$(MODE)/test/libc/str: \ + $(TEST_LIBC_STR_BINS) \ $(TEST_LIBC_STR_CHECKS) diff --git a/test/net/https/mbedtls_test.c b/test/net/https/mbedtls_test.c index 049828cb5..0ac234712 100644 --- a/test/net/https/mbedtls_test.c +++ b/test/net/https/mbedtls_test.c @@ -19,12 +19,14 @@ #include "libc/bits/bits.h" #include "libc/bits/bswap.h" #include "libc/macros.internal.h" +#include "libc/nexgen32e/crc32.h" #include "libc/nexgen32e/nexgen32e.h" #include "libc/nexgen32e/x86feature.h" #include "libc/nt/typedef/imagetlscallback.h" #include "libc/rand/rand.h" #include "libc/runtime/gc.internal.h" #include "libc/runtime/runtime.h" +#include "libc/str/blake2.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/hyperion.h" #include "libc/testlib/testlib.h" @@ -257,6 +259,8 @@ BENCH(mbedtls, bench) { mbedtls_sha512_ret(kHyperion, kHyperionSize, d, 1)); EZBENCH2("sha512", donothing, mbedtls_sha512_ret(kHyperion, kHyperionSize, d, 0)); + EZBENCH2("BLAKE2B256", donothing, BLAKE2B256(kHyperion, kHyperionSize, d)); + EZBENCH2("crc32_z", donothing, crc32_z(0, kHyperion, kHyperionSize)); } char *mpi2str(mbedtls_mpi *m) { diff --git a/third_party/mbedtls/blake2b256.c b/third_party/mbedtls/blake2b256.c new file mode 100644 index 000000000..2ffec50a8 --- /dev/null +++ b/third_party/mbedtls/blake2b256.c @@ -0,0 +1,33 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:4;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2021 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/str/blake2.h" +#include "third_party/mbedtls/md.h" +/* clang-format off */ + +const mbedtls_md_info_t mbedtls_blake2b256_info = { + "BLAKE2B256", + MBEDTLS_MD_BLAKE2B256, + BLAKE2B256_DIGEST_LENGTH, + BLAKE2B_CBLOCK, + (void *)BLAKE2B256_Init, + (void *)BLAKE2B256_Update, + (void *)BLAKE2B256_Process, + (void *)BLAKE2B256_Final, + (void *)BLAKE2B256, +}; diff --git a/third_party/mbedtls/config.h b/third_party/mbedtls/config.h index ab7f15e3e..367242e09 100644 --- a/third_party/mbedtls/config.h +++ b/third_party/mbedtls/config.h @@ -19,10 +19,12 @@ #endif /* hash functions */ -#define MBEDTLS_MD5_C #define MBEDTLS_SHA1_C #define MBEDTLS_SHA256_C #define MBEDTLS_SHA512_C +#ifdef MBEDTLS_SSL_PROTO_TLS1 +#define MBEDTLS_MD5_C +#endif /* random numbers */ #define ENTROPY_HAVE_STRONG diff --git a/third_party/mbedtls/md.c b/third_party/mbedtls/md.c index a180ebc3b..c9fa10f92 100644 --- a/third_party/mbedtls/md.c +++ b/third_party/mbedtls/md.c @@ -17,6 +17,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/mem/mem.h" #include "libc/stdio/stdio.h" +#include "libc/str/blake2.h" #include "third_party/mbedtls/common.h" #include "third_party/mbedtls/error.h" #include "third_party/mbedtls/md.h" @@ -69,6 +70,7 @@ asm(".include \"libc/disclaimer.inc\""); * Reminder: update profiles in x509_crt.c when adding a new hash! */ static const uint8_t supported_digests[] = { + MBEDTLS_MD_BLAKE2B256, #if defined(MBEDTLS_SHA512_C) MBEDTLS_MD_SHA512, #if !defined(MBEDTLS_SHA512_NO_SHA384) @@ -154,6 +156,8 @@ const mbedtls_md_info_t *mbedtls_md_info_from_string( const char *md_name ) if( !strcasecmp( "SHA512", md_name ) ) return mbedtls_md_info_from_type( MBEDTLS_MD_SHA512 ); #endif + if( !strcasecmp( "BLAKE2B256", md_name ) ) + return mbedtls_md_info_from_type( MBEDTLS_MD_BLAKE2B256 ); return( NULL ); } @@ -200,6 +204,8 @@ const mbedtls_md_info_t *mbedtls_md_info_from_type( mbedtls_md_type_t md_type ) case MBEDTLS_MD_SHA512: return( &mbedtls_sha512_info ); #endif + case MBEDTLS_MD_BLAKE2B256: + return( &mbedtls_blake2b256_info ); default: return( NULL ); } @@ -237,6 +243,8 @@ static int16_t GetMdContextSize(mbedtls_md_type_t t) case MBEDTLS_MD_SHA512: return sizeof(mbedtls_sha512_context); #endif + case MBEDTLS_MD_BLAKE2B256: + return sizeof(struct Blake2b); default: return( MBEDTLS_ERR_MD_BAD_INPUT_DATA ); } diff --git a/third_party/mbedtls/md.h b/third_party/mbedtls/md.h index e36d0e761..87f22e9d4 100644 --- a/third_party/mbedtls/md.h +++ b/third_party/mbedtls/md.h @@ -18,19 +18,19 @@ COSMOPOLITAN_C_START_ * \warning MD2, MD4, MD5 and SHA-1 are considered weak message digests and * their use constitutes a security risk. We recommend considering * stronger message digests instead. - * */ typedef enum { - MBEDTLS_MD_NONE=0, /**< None. */ - MBEDTLS_MD_SHA1, /**< The SHA-1 message digest. */ - MBEDTLS_MD_SHA224, /**< The SHA-224 message digest. */ - MBEDTLS_MD_SHA256, /**< The SHA-256 message digest. */ - MBEDTLS_MD_SHA384, /**< The SHA-384 message digest. */ - MBEDTLS_MD_SHA512, /**< The SHA-512 message digest. */ - MBEDTLS_MD_RIPEMD160, /**< The RIPEMD-160 message digest. */ - MBEDTLS_MD_MD2, /**< The MD2 message digest. */ - MBEDTLS_MD_MD4, /**< The MD4 message digest. */ - MBEDTLS_MD_MD5, /**< The MD5 message digest. */ + MBEDTLS_MD_NONE=0, /**< None. */ + MBEDTLS_MD_SHA1, /**< The SHA-1 message digest. */ + MBEDTLS_MD_SHA224, /**< The SHA-224 message digest. */ + MBEDTLS_MD_SHA256, /**< The SHA-256 message digest. */ + MBEDTLS_MD_SHA384, /**< The SHA-384 message digest. */ + MBEDTLS_MD_SHA512, /**< The SHA-512 message digest. */ + MBEDTLS_MD_BLAKE2B256, /**< The BLAKE2B256 message digest. */ + MBEDTLS_MD_RIPEMD160, /**< The RIPEMD-160 message digest. */ + MBEDTLS_MD_MD2, /**< The MD2 message digest. */ + MBEDTLS_MD_MD4, /**< The MD4 message digest. */ + MBEDTLS_MD_MD5, /**< The MD5 message digest. */ } mbedtls_md_type_t; #if defined(MBEDTLS_SHA512_C) @@ -294,6 +294,7 @@ extern const mbedtls_md_info_t mbedtls_sha224_info; extern const mbedtls_md_info_t mbedtls_sha256_info; extern const mbedtls_md_info_t mbedtls_sha384_info; extern const mbedtls_md_info_t mbedtls_sha512_info; +extern const mbedtls_md_info_t mbedtls_blake2b256_info; COSMOPOLITAN_C_END_ #endif /* COSMOPOLITAN_THIRD_PARTY_MBEDTLS_MD_H_ */ diff --git a/third_party/mbedtls/pem.c b/third_party/mbedtls/pem.c index 37025cf71..448089d0a 100644 --- a/third_party/mbedtls/pem.c +++ b/third_party/mbedtls/pem.c @@ -125,7 +125,7 @@ static int pem_des_decrypt( unsigned char des_iv[8], if( ( ret = mbedtls_des_setkey_dec( &des_ctx, des_key ) ) != 0 ) goto exit; ret = mbedtls_des_crypt_cbc( &des_ctx, MBEDTLS_DES_DECRYPT, buflen, - des_iv, buf, buf ); + des_iv, buf, buf ); exit: mbedtls_des_free( &des_ctx ); mbedtls_platform_zeroize( des_key, 8 ); diff --git a/third_party/python/Include/import.h b/third_party/python/Include/import.h index 9b772d3eb..5e844880a 100644 --- a/third_party/python/Include/import.h +++ b/third_party/python/Include/import.h @@ -107,7 +107,7 @@ struct _inittab { const char *name; /* ASCII encoded string */ PyObject* (*initfunc)(void); }; -extern struct _inittab _PyImport_Inittab[]; +extern const struct _inittab _PyImport_Inittab[]; extern struct _inittab * PyImport_Inittab; int PyImport_ExtendInittab(struct _inittab *newtab); #endif /* Py_LIMITED_API */ diff --git a/third_party/python/Include/pylifecycle.h b/third_party/python/Include/pylifecycle.h index 31d15aaf3..9deffbc08 100644 --- a/third_party/python/Include/pylifecycle.h +++ b/third_party/python/Include/pylifecycle.h @@ -59,6 +59,7 @@ wchar_t * Py_GetPrefix(void); wchar_t * Py_GetExecPrefix(void); wchar_t * Py_GetPath(void); void Py_SetPath(const wchar_t *); +void Py_LimitedPath(void); #ifdef MS_WINDOWS int _Py_CheckPython3(); #endif diff --git a/third_party/python/Lib/_bootlocale.py b/third_party/python/Lib/_bootlocale.py index da07da861..ba682c437 100644 --- a/third_party/python/Lib/_bootlocale.py +++ b/third_party/python/Lib/_bootlocale.py @@ -7,28 +7,15 @@ Don't import directly from third-party code; use the `locale` module instead! import sys import _locale -if sys.platform.startswith("win"): - def getpreferredencoding(do_setlocale=True): - return _locale._getdefaultlocale()[1] -else: - try: - _locale.CODESET - except AttributeError: - def getpreferredencoding(do_setlocale=True): - # This path for legacy systems needs the more complex - # getdefaultlocale() function, import the full locale module. - import locale - return locale.getpreferredencoding(do_setlocale) - else: - def getpreferredencoding(do_setlocale=True): - assert not do_setlocale - result = _locale.nl_langinfo(_locale.CODESET) - if not result and sys.platform in ('darwin', 'cosmo'): - # nl_langinfo can return an empty string - # when the setting has an invalid value. - # Default to UTF-8 in that case because - # UTF-8 is the default charset on OSX and - # returning nothing will crash the - # interpreter. - result = 'UTF-8' - return result +def getpreferredencoding(do_setlocale=True): + assert not do_setlocale + result = _locale.nl_langinfo(_locale.CODESET) + if not result and sys.platform in ('darwin', 'cosmo'): + # nl_langinfo can return an empty string + # when the setting has an invalid value. + # Default to UTF-8 in that case because + # UTF-8 is the default charset on OSX and + # returning nothing will crash the + # interpreter. + result = 'UTF-8' + return result diff --git a/third_party/python/Lib/_strptime.py b/third_party/python/Lib/_strptime.py index fe9436115..65615003b 100644 --- a/third_party/python/Lib/_strptime.py +++ b/third_party/python/Lib/_strptime.py @@ -11,7 +11,7 @@ FUNCTIONS: """ import time -import locale +# import locale import calendar from re import compile as re_compile from re import IGNORECASE @@ -28,7 +28,8 @@ __all__ = [] def _getlang(): # Figure out what the current language is set to. - return locale.getlocale(locale.LC_TIME) + # return locale.getlocale(locale.LC_TIME) + return (None, None) class LocaleTime(object): """Stores and handles locale-specific information related to time. diff --git a/third_party/python/Lib/collections/__init__.py b/third_party/python/Lib/collections/__init__.py index b2c159422..1d6621659 100644 --- a/third_party/python/Lib/collections/__init__.py +++ b/third_party/python/Lib/collections/__init__.py @@ -39,17 +39,10 @@ from _weakref import proxy as _proxy from itertools import repeat as _repeat, chain as _chain, starmap as _starmap from reprlib import recursive_repr as _recursive_repr -try: - from _collections import deque -except ImportError: - pass -else: - MutableSequence.register(deque) +from _collections import deque +MutableSequence.register(deque) -try: - from _collections import defaultdict -except ImportError: - pass +from _collections import defaultdict ################################################################################ diff --git a/third_party/python/Lib/hashlib.py b/third_party/python/Lib/hashlib.py index 4a2e2e382..51a758def 100644 --- a/third_party/python/Lib/hashlib.py +++ b/third_party/python/Lib/hashlib.py @@ -11,8 +11,7 @@ new(name, data=b'', **kwargs) - returns a new hash object implementing the Named constructor functions are also available, these are faster than using new(name): -md5(), sha1(), sha224(), sha256(), sha384(), sha512(), -sha3_224, sha3_256, sha3_384, sha3_512, shake_128, and shake_256. +md5(), sha1(), sha224(), sha256(), sha384(), sha512(), and blake2b256(). More algorithms may be available on your platform but the above are guaranteed to exist. See the algorithms_guaranteed and algorithms_available attributes @@ -56,9 +55,7 @@ More condensed: # This tuple and __get_builtin_constructor() must be modified if a new # always available algorithm is added. __always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512', - 'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', - 'shake_128', 'shake_256') - + 'blake2b256') algorithms_guaranteed = set(__always_supported) algorithms_available = set(__always_supported) @@ -73,23 +70,12 @@ def __get_builtin_constructor(name): constructor = cache.get(name) if constructor is not None: return constructor - try: - if name in ('SHA1', 'sha1'): - import _sha1 - cache['SHA1'] = cache['sha1'] = _sha1.sha1 - elif name in ('MD5', 'md5'): - import _md5 - cache['MD5'] = cache['md5'] = _md5.md5 - elif name in ('SHA256', 'sha256', 'SHA224', 'sha224'): - import _sha256 - cache['SHA224'] = cache['sha224'] = _sha256.sha224 - cache['SHA256'] = cache['sha256'] = _sha256.sha256 - elif name in ('SHA512', 'sha512', 'SHA384', 'sha384'): - import _sha512 - cache['SHA384'] = cache['sha384'] = _sha512.sha384 - cache['SHA512'] = cache['sha512'] = _sha512.sha512 - elif name in {'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', - 'shake_128', 'shake_256'}: + if name in ('MD5', 'md5'): + import _md5 + cache['MD5'] = cache['md5'] = _md5.md5 + elif name in {'sha3_224', 'sha3_256', 'sha3_384', 'sha3_512', + 'shake_128', 'shake_256'}: + try: import _sha3 cache['sha3_224'] = _sha3.sha3_224 cache['sha3_256'] = _sha3.sha3_256 @@ -97,21 +83,19 @@ def __get_builtin_constructor(name): cache['sha3_512'] = _sha3.sha3_512 cache['shake_128'] = _sha3.shake_128 cache['shake_256'] = _sha3.shake_256 - except ImportError: - pass # no extension module, this hash is unsupported. - + except ImportError: + raise ValueError('unsupported hash type ' + name) constructor = cache.get(name) if constructor is not None: return constructor - raise ValueError('unsupported hash type ' + name) -def __get_openssl_constructor(name): +def __get_mbedtls_constructor(name): try: - f = getattr(_hashlib, 'openssl_' + name) + f = getattr(_hashlib, 'mbedtls_' + name) # Allow the C module to raise ValueError. The function will be - # defined but the hash not actually available thanks to OpenSSL. + # defined but the hash not actually available thanks to Mbedtls. f() # Use the C function directly (very fast) return f @@ -134,25 +118,21 @@ def __hash_new(name, data=b'', **kwargs): try: return _hashlib.new(name, data) except ValueError: - # If the _hashlib module (OpenSSL) doesn't support the named + # If the _hashlib module (Mbedtls) doesn't support the named # hash, try using our builtin implementations. # This allows for SHA224/256 and SHA384/512 support even though - # the OpenSSL library prior to 0.9.8 doesn't provide them. + # the Mbedtls library prior to 0.9.8 doesn't provide them. return __get_builtin_constructor(name)(data) -try: - import _hashlib - new = __hash_new - __get_hash = __get_openssl_constructor - algorithms_available = algorithms_available.union( - _hashlib.openssl_md_meth_names) -except ImportError: - new = __py_new - __get_hash = __get_builtin_constructor +import _hashlib +new = __hash_new +__get_hash = __get_mbedtls_constructor +algorithms_available = algorithms_available.union( + _hashlib.mbedtls_md_meth_names) try: - # OpenSSL's PKCS5_PBKDF2_HMAC requires OpenSSL 1.0+ with HMAC and SHA + # Mbedtls's PKCS5_PBKDF2_HMAC requires Mbedtls 1.0+ with HMAC and SHA from _hashlib import pbkdf2_hmac except ImportError: _trans_5C = bytes((x ^ 0x5C) for x in range(256)) @@ -162,7 +142,7 @@ except ImportError: """Password based key derivation function 2 (PKCS #5 v2.0) This Python implementations based on the hmac module about as fast - as OpenSSL's PKCS5_PBKDF2_HMAC for short passwords and much faster + as Mbedtls's PKCS5_PBKDF2_HMAC for short passwords and much faster for long passwords. """ if not isinstance(hash_name, str): @@ -216,26 +196,19 @@ except ImportError: return dkey[:dklen] try: - # OpenSSL's scrypt requires OpenSSL 1.1+ + # Mbedtls's scrypt requires Mbedtls 1.1+ from _hashlib import scrypt except ImportError: pass - md5 = __get_hash('md5') sha1 = __get_hash('sha1') sha224 = __get_hash('sha224') sha256 = __get_hash('sha256') sha384 = __get_hash('sha384') sha512 = __get_hash('sha512') -sha3_224 = __get_hash('sha3_224') -sha3_256 = __get_hash('sha3_256') -sha3_384 = __get_hash('sha3_384') -sha3_512 = __get_hash('sha3_512') -shake_128 = __get_hash('shake_128') -shake_256 = __get_hash('shake_256') - +blake2b256 = __get_hash('blake2b256') # Cleanup locals() del __always_supported, __get_hash -del __py_new, __hash_new, __get_openssl_constructor +del __py_new, __hash_new, __get_mbedtls_constructor diff --git a/third_party/python/Lib/hello.py b/third_party/python/Lib/hello.py new file mode 100644 index 000000000..8cde7829c --- /dev/null +++ b/third_party/python/Lib/hello.py @@ -0,0 +1 @@ +print("hello world") diff --git a/third_party/python/Lib/importlib/_bootstrap_external.py b/third_party/python/Lib/importlib/_bootstrap_external.py index a65790d09..41e494600 100644 --- a/third_party/python/Lib/importlib/_bootstrap_external.py +++ b/third_party/python/Lib/importlib/_bootstrap_external.py @@ -1364,7 +1364,7 @@ def _get_supported_file_loaders(): extensions = ExtensionFileLoader, _imp.extension_suffixes() source = SourceFileLoader, SOURCE_SUFFIXES bytecode = SourcelessFileLoader, BYTECODE_SUFFIXES - return [extensions, bytecode, source] + return [bytecode, extensions, source] def _setup(_bootstrap_module): diff --git a/third_party/python/Lib/launchpy.py b/third_party/python/Lib/launchpy.py new file mode 100644 index 000000000..1ea390070 --- /dev/null +++ b/third_party/python/Lib/launchpy.py @@ -0,0 +1,15 @@ +import sys +from importlib import _bootstrap_external + +def run_module_as_main(mod_name): + path = "/zip/.python/%s.pyc" % (mod_name.replace(".", "/")) + loader = _bootstrap_external.SourcelessFileLoader(mod_name, path) + code = loader.get_code(mod_name) + globs = sys.modules["__main__"].__dict__ + globs["__name__"] = "__main__" + globs["__file__"] = path + globs["__package__"] = None + globs["__loader__"] = loader + globs["__spec__"] = None + exec(code, globs) + return globs diff --git a/third_party/python/Lib/os.py b/third_party/python/Lib/os.py index d246204ed..afb8425d8 100644 --- a/third_party/python/Lib/os.py +++ b/third_party/python/Lib/os.py @@ -1158,7 +1158,10 @@ def popen(cmd, mode="r", buffering=-1): raise ValueError("invalid mode %r" % mode) if buffering == 0 or buffering is None: raise ValueError("popen() does not support unbuffered streams") - import subprocess, io + try: + import subprocess, io + except ImportError: + raise ImportError('please use subprocess module') if mode == "r": proc = subprocess.Popen(cmd, shell=True, diff --git a/third_party/python/Lib/pydoc.py b/third_party/python/Lib/pydoc.py index 5247ef9ea..65e7acf62 100644 --- a/third_party/python/Lib/pydoc.py +++ b/third_party/python/Lib/pydoc.py @@ -2193,10 +2193,13 @@ def _start_server(urlhandler, port): >>> print(serverthread.error) None """ - import http.server - import email.message - import select - import threading + try: + import http.server + import email.message + import select + import threading + except ImportError: + sys.exit(1) class DocHandler(http.server.BaseHTTPRequestHandler): diff --git a/third_party/python/Lib/shutil.py b/third_party/python/Lib/shutil.py index dd1244845..2bc81be7b 100644 --- a/third_party/python/Lib/shutil.py +++ b/third_party/python/Lib/shutil.py @@ -626,7 +626,10 @@ def _make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0, raise ValueError("bad value for 'compress', or compression format not " "supported : {0}".format(compress)) - import tarfile # late import for breaking circular dependency + try: + import tarfile + except ImportError: + raise compress_ext = '.' + tar_compression if compress else '' archive_name = base_name + '.tar' + compress_ext @@ -669,7 +672,10 @@ def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None): The output zip file will be named 'base_name' + ".zip". Returns the name of the output zip file. """ - import zipfile # late import for breaking circular dependency + try: + import zipfile + except ImportError: + raise zip_filename = base_name + ".zip" archive_dir = os.path.dirname(base_name) @@ -877,7 +883,10 @@ def _ensure_directory(path): def _unpack_zipfile(filename, extract_dir): """Unpack zip `filename` to `extract_dir` """ - import zipfile # late import for breaking circular dependency + try: + import zipfile + except ImportError: + raise if not zipfile.is_zipfile(filename): raise ReadError("%s is not a zip file" % filename) @@ -911,7 +920,10 @@ def _unpack_zipfile(filename, extract_dir): def _unpack_tarfile(filename, extract_dir): """Unpack tar/tar.gz/tar.bz2/tar.xz `filename` to `extract_dir` """ - import tarfile # late import for breaking circular dependency + try: + import tarfile + except ImportError: + raise try: tarobj = tarfile.open(filename) except tarfile.TarError: @@ -1003,22 +1015,6 @@ if hasattr(os, 'statvfs'): used = (st.f_blocks - st.f_bfree) * st.f_frsize return _ntuple_diskusage(total, used, free) -elif os.name == 'nt': - - import nt - __all__.append('disk_usage') - _ntuple_diskusage = collections.namedtuple('usage', 'total used free') - - def disk_usage(path): - """Return disk usage statistics about the given path. - - Returned values is a named tuple with attributes 'total', 'used' and - 'free', which are the amount of total, used and free space, in bytes. - """ - total, free = nt._getdiskusage(path) - used = total - free - return _ntuple_diskusage(total, used, free) - def chown(path, user=None, group=None): """Change owner user and group of the given path. diff --git a/third_party/python/Modules/_bisectmodule.c b/third_party/python/Modules/_bisectmodule.c index 802170dbd..2fbe13aa1 100644 --- a/third_party/python/Modules/_bisectmodule.c +++ b/third_party/python/Modules/_bisectmodule.c @@ -6,6 +6,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #define PY_SSIZE_T_CLEAN #include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/object.h" @@ -282,3 +283,8 @@ PyInit__bisect(void) { return PyModule_Create(&_bisectmodule); } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__bisect = { + "_bisect", + PyInit__bisect, +}; diff --git a/third_party/python/Modules/_bz2module.c b/third_party/python/Modules/_bz2module.c index 52596a17a..e08e160ca 100644 --- a/third_party/python/Modules/_bz2module.c +++ b/third_party/python/Modules/_bz2module.c @@ -9,6 +9,7 @@ #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/bytesobject.h" #include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/object.h" #include "third_party/python/Include/pyerrors.h" @@ -814,3 +815,8 @@ PyInit__bz2(void) return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__bz2 = { + "_bz2", + PyInit__bz2, +}; diff --git a/third_party/python/Modules/_codecsmodule.c b/third_party/python/Modules/_codecsmodule.c index 1180b8098..6c5d8e1a4 100644 --- a/third_party/python/Modules/_codecsmodule.c +++ b/third_party/python/Modules/_codecsmodule.c @@ -8,6 +8,7 @@ #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/bytesobject.h" #include "third_party/python/Include/codecs.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/object.h" #include "third_party/python/Include/pyerrors.h" diff --git a/third_party/python/Modules/_collectionsmodule.c b/third_party/python/Modules/_collectionsmodule.c index c31f4025d..da0fc344e 100644 --- a/third_party/python/Modules/_collectionsmodule.c +++ b/third_party/python/Modules/_collectionsmodule.c @@ -4,6 +4,7 @@ #include "third_party/python/Include/ceval.h" #include "third_party/python/Include/descrobject.h" #include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/object.h" diff --git a/third_party/python/Modules/_csv.c b/third_party/python/Modules/_csv.c index 2753f0327..70886ee2b 100644 --- a/third_party/python/Modules/_csv.c +++ b/third_party/python/Modules/_csv.c @@ -7,6 +7,7 @@ #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/descrobject.h" #include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/listobject.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" @@ -1715,3 +1716,8 @@ PyInit__csv(void) PyModule_AddObject(module, "Error", _csvstate(module)->error_obj); return module; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__csv = { + "_csv", + PyInit__csv, +}; diff --git a/third_party/python/Modules/_curses_panel.c b/third_party/python/Modules/_curses_panel.c deleted file mode 100644 index c2f768a32..000000000 --- a/third_party/python/Modules/_curses_panel.c +++ /dev/null @@ -1,552 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Python 3 │ -│ https://docs.python.org/3/license.html │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "third_party/python/Include/yoink.h" -/* clang-format off */ - -PYTHON_PROVIDE("_curses_panel"); -PYTHON_PROVIDE("_curses_panel.bottom_panel"); -PYTHON_PROVIDE("_curses_panel.error"); -PYTHON_PROVIDE("_curses_panel.new_panel"); -PYTHON_PROVIDE("_curses_panel.top_panel"); -PYTHON_PROVIDE("_curses_panel.update_panels"); -PYTHON_PROVIDE("_curses_panel.version"); - -/* - * Interface to the ncurses panel library - * - * Original version by Thomas Gellekum - */ - -/* Release Number */ - -static const char PyCursesVersion[] = "2.1"; - -/* Includes */ - -#include "third_party/python/Include/Python.h" - -#include "third_party/python/Include/py_curses.h" - -typedef struct { - PyObject *PyCursesError; - PyObject *PyCursesPanel_Type; -} _curses_panelstate; - -#define _curses_panelstate(o) ((_curses_panelstate *)PyModule_GetState(o)) - -static int -_curses_panel_clear(PyObject *m) -{ - Py_CLEAR(_curses_panelstate(m)->PyCursesError); - return 0; -} - -static int -_curses_panel_traverse(PyObject *m, visitproc visit, void *arg) -{ - Py_VISIT(_curses_panelstate(m)->PyCursesError); - return 0; -} - -static void -_curses_panel_free(void *m) -{ - _curses_panel_clear((PyObject *) m); -} - -static struct PyModuleDef _curses_panelmodule; - -#define _curses_panelstate_global \ -((_curses_panelstate *) PyModule_GetState(PyState_FindModule(&_curses_panelmodule))) - -/* Utility Functions */ - -/* - * Check the return code from a curses function and return None - * or raise an exception as appropriate. - */ - -static PyObject * -PyCursesCheckERR(int code, const char *fname) -{ - if (code != ERR) { - Py_INCREF(Py_None); - return Py_None; - } else { - if (fname == NULL) { - PyErr_SetString(_curses_panelstate_global->PyCursesError, catchall_ERR); - } else { - PyErr_Format(_curses_panelstate_global->PyCursesError, "%s() returned ERR", fname); - } - return NULL; - } -} - -/***************************************************************************** - The Panel Object -******************************************************************************/ - -/* Definition of the panel object and panel type */ - -typedef struct { - PyObject_HEAD - PANEL *pan; - PyCursesWindowObject *wo; /* for reference counts */ -} PyCursesPanelObject; - -#define PyCursesPanel_Check(v) \ - (Py_TYPE(v) == _curses_panelstate_global->PyCursesPanel_Type) - -/* Some helper functions. The problem is that there's always a window - associated with a panel. To ensure that Python's GC doesn't pull - this window from under our feet we need to keep track of references - to the corresponding window object within Python. We can't use - dupwin(oldwin) to keep a copy of the curses WINDOW because the - contents of oldwin is copied only once; code like - - win = newwin(...) - pan = win.panel() - win.addstr(some_string) - pan.window().addstr(other_string) - - will fail. */ - -/* We keep a linked list of PyCursesPanelObjects, lop. A list should - suffice, I don't expect more than a handful or at most a few - dozens of panel objects within a typical program. */ -typedef struct _list_of_panels { - PyCursesPanelObject *po; - struct _list_of_panels *next; -} list_of_panels; - -/* list anchor */ -static list_of_panels *lop; - -/* Insert a new panel object into lop */ -static int -insert_lop(PyCursesPanelObject *po) -{ - list_of_panels *new; - - if ((new = (list_of_panels *)PyMem_Malloc(sizeof(list_of_panels))) == NULL) { - PyErr_NoMemory(); - return -1; - } - new->po = po; - new->next = lop; - lop = new; - return 0; -} - -/* Remove the panel object from lop */ -static void -remove_lop(PyCursesPanelObject *po) -{ - list_of_panels *temp, *n; - - temp = lop; - if (temp->po == po) { - lop = temp->next; - PyMem_Free(temp); - return; - } - while (temp->next == NULL || temp->next->po != po) { - if (temp->next == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "remove_lop: can't find Panel Object"); - return; - } - temp = temp->next; - } - n = temp->next->next; - PyMem_Free(temp->next); - temp->next = n; - return; -} - -/* Return the panel object that corresponds to pan */ -static PyCursesPanelObject * -find_po(PANEL *pan) -{ - list_of_panels *temp; - for (temp = lop; temp->po->pan != pan; temp = temp->next) - if (temp->next == NULL) return NULL; /* not found!? */ - return temp->po; -} - -/* Function Prototype Macros - They are ugly but very, very useful. ;-) - - X - function name - TYPE - parameter Type - ERGSTR - format string for construction of the return value - PARSESTR - format string for argument parsing */ - -#define Panel_NoArgNoReturnFunction(X) \ -static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self) \ -{ return PyCursesCheckERR(X(self->pan), # X); } - -#define Panel_NoArgTrueFalseFunction(X) \ -static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self) \ -{ \ - if (X (self->pan) == FALSE) { Py_INCREF(Py_False); return Py_False; } \ - else { Py_INCREF(Py_True); return Py_True; } } - -#define Panel_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \ -static PyObject *PyCursesPanel_##X(PyCursesPanelObject *self, PyObject *args) \ -{ \ - TYPE arg1, arg2; \ - if (!PyArg_ParseTuple(args, PARSESTR, &arg1, &arg2)) return NULL; \ - return PyCursesCheckERR(X(self->pan, arg1, arg2), # X); } - -/* ------------- PANEL routines --------------- */ - -Panel_NoArgNoReturnFunction(bottom_panel) -Panel_NoArgNoReturnFunction(hide_panel) -Panel_NoArgNoReturnFunction(show_panel) -Panel_NoArgNoReturnFunction(top_panel) -Panel_NoArgTrueFalseFunction(panel_hidden) -Panel_TwoArgNoReturnFunction(move_panel, int, "ii;y,x") - -/* Allocation and deallocation of Panel Objects */ - -static PyObject * -PyCursesPanel_New(PANEL *pan, PyCursesWindowObject *wo) -{ - PyCursesPanelObject *po; - - po = PyObject_NEW(PyCursesPanelObject, - (PyTypeObject *)(_curses_panelstate_global)->PyCursesPanel_Type); - if (po == NULL) return NULL; - po->pan = pan; - if (insert_lop(po) < 0) { - po->wo = NULL; - Py_DECREF(po); - return NULL; - } - po->wo = wo; - Py_INCREF(wo); - return (PyObject *)po; -} - -static void -PyCursesPanel_Dealloc(PyCursesPanelObject *po) -{ - PyObject *obj = (PyObject *) panel_userptr(po->pan); - if (obj) { - (void)set_panel_userptr(po->pan, NULL); - Py_DECREF(obj); - } - (void)del_panel(po->pan); - if (po->wo != NULL) { - Py_DECREF(po->wo); - remove_lop(po); - } - PyObject_DEL(po); -} - -/* panel_above(NULL) returns the bottom panel in the stack. To get - this behaviour we use curses.panel.bottom_panel(). */ -static PyObject * -PyCursesPanel_above(PyCursesPanelObject *self) -{ - PANEL *pan; - PyCursesPanelObject *po; - - pan = panel_above(self->pan); - - if (pan == NULL) { /* valid output, it means the calling panel - is on top of the stack */ - Py_INCREF(Py_None); - return Py_None; - } - po = find_po(pan); - if (po == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "panel_above: can't find Panel Object"); - return NULL; - } - Py_INCREF(po); - return (PyObject *)po; -} - -/* panel_below(NULL) returns the top panel in the stack. To get - this behaviour we use curses.panel.top_panel(). */ -static PyObject * -PyCursesPanel_below(PyCursesPanelObject *self) -{ - PANEL *pan; - PyCursesPanelObject *po; - - pan = panel_below(self->pan); - - if (pan == NULL) { /* valid output, it means the calling panel - is on the bottom of the stack */ - Py_INCREF(Py_None); - return Py_None; - } - po = find_po(pan); - if (po == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "panel_below: can't find Panel Object"); - return NULL; - } - Py_INCREF(po); - return (PyObject *)po; -} - -static PyObject * -PyCursesPanel_window(PyCursesPanelObject *self) -{ - Py_INCREF(self->wo); - return (PyObject *)self->wo; -} - -static PyObject * -PyCursesPanel_replace_panel(PyCursesPanelObject *self, PyObject *args) -{ - PyCursesPanelObject *po; - PyCursesWindowObject *temp; - int rtn; - - if (PyTuple_Size(args) != 1) { - PyErr_SetString(PyExc_TypeError, "replace requires one argument"); - return NULL; - } - if (!PyArg_ParseTuple(args, "O!;window object", - &PyCursesWindow_Type, &temp)) - return NULL; - - po = find_po(self->pan); - if (po == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "replace_panel: can't find Panel Object"); - return NULL; - } - - rtn = replace_panel(self->pan, temp->win); - if (rtn == ERR) { - PyErr_SetString(_curses_panelstate_global->PyCursesError, "replace_panel() returned ERR"); - return NULL; - } - Py_INCREF(temp); - Py_SETREF(po->wo, temp); - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject * -PyCursesPanel_set_panel_userptr(PyCursesPanelObject *self, PyObject *obj) -{ - PyObject *oldobj; - int rc; - PyCursesInitialised; - Py_INCREF(obj); - oldobj = (PyObject *) panel_userptr(self->pan); - rc = set_panel_userptr(self->pan, (void*)obj); - if (rc == ERR) { - /* In case of an ncurses error, decref the new object again */ - Py_DECREF(obj); - } - Py_XDECREF(oldobj); - return PyCursesCheckERR(rc, "set_panel_userptr"); -} - -static PyObject * -PyCursesPanel_userptr(PyCursesPanelObject *self) -{ - PyObject *obj; - PyCursesInitialised; - obj = (PyObject *) panel_userptr(self->pan); - if (obj == NULL) { - PyErr_SetString(_curses_panelstate_global->PyCursesError, "no userptr set"); - return NULL; - } - - Py_INCREF(obj); - return obj; -} - - -/* Module interface */ - -static PyMethodDef PyCursesPanel_Methods[] = { - {"above", (PyCFunction)PyCursesPanel_above, METH_NOARGS}, - {"below", (PyCFunction)PyCursesPanel_below, METH_NOARGS}, - {"bottom", (PyCFunction)PyCursesPanel_bottom_panel, METH_NOARGS}, - {"hidden", (PyCFunction)PyCursesPanel_panel_hidden, METH_NOARGS}, - {"hide", (PyCFunction)PyCursesPanel_hide_panel, METH_NOARGS}, - {"move", (PyCFunction)PyCursesPanel_move_panel, METH_VARARGS}, - {"replace", (PyCFunction)PyCursesPanel_replace_panel, METH_VARARGS}, - {"set_userptr", (PyCFunction)PyCursesPanel_set_panel_userptr, METH_O}, - {"show", (PyCFunction)PyCursesPanel_show_panel, METH_NOARGS}, - {"top", (PyCFunction)PyCursesPanel_top_panel, METH_NOARGS}, - {"userptr", (PyCFunction)PyCursesPanel_userptr, METH_NOARGS}, - {"window", (PyCFunction)PyCursesPanel_window, METH_NOARGS}, - {NULL, NULL} /* sentinel */ -}; - -/* -------------------------------------------------------*/ - -static PyType_Slot PyCursesPanel_Type_slots[] = { - {Py_tp_dealloc, PyCursesPanel_Dealloc}, - {Py_tp_methods, PyCursesPanel_Methods}, - {0, 0}, -}; - -static PyType_Spec PyCursesPanel_Type_spec = { - "_curses_panel.curses panel", - sizeof(PyCursesPanelObject), - 0, - Py_TPFLAGS_DEFAULT, - PyCursesPanel_Type_slots -}; - -/* Wrapper for panel_above(NULL). This function returns the bottom - panel of the stack, so it's renamed to bottom_panel(). - panel.above() *requires* a panel object in the first place which - may be undesirable. */ -static PyObject * -PyCurses_bottom_panel(PyObject *self) -{ - PANEL *pan; - PyCursesPanelObject *po; - - PyCursesInitialised; - - pan = panel_above(NULL); - - if (pan == NULL) { /* valid output, it means - there's no panel at all */ - Py_INCREF(Py_None); - return Py_None; - } - po = find_po(pan); - if (po == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "panel_above: can't find Panel Object"); - return NULL; - } - Py_INCREF(po); - return (PyObject *)po; -} - -static PyObject * -PyCurses_new_panel(PyObject *self, PyObject *args) -{ - PyCursesWindowObject *win; - PANEL *pan; - - if (!PyArg_ParseTuple(args, "O!", &PyCursesWindow_Type, &win)) - return NULL; - pan = new_panel(win->win); - if (pan == NULL) { - PyErr_SetString(_curses_panelstate_global->PyCursesError, catchall_NULL); - return NULL; - } - return (PyObject *)PyCursesPanel_New(pan, win); -} - - -/* Wrapper for panel_below(NULL). This function returns the top panel - of the stack, so it's renamed to top_panel(). panel.below() - *requires* a panel object in the first place which may be - undesirable. */ -static PyObject * -PyCurses_top_panel(PyObject *self) -{ - PANEL *pan; - PyCursesPanelObject *po; - - PyCursesInitialised; - - pan = panel_below(NULL); - - if (pan == NULL) { /* valid output, it means - there's no panel at all */ - Py_INCREF(Py_None); - return Py_None; - } - po = find_po(pan); - if (po == NULL) { - PyErr_SetString(PyExc_RuntimeError, - "panel_below: can't find Panel Object"); - return NULL; - } - Py_INCREF(po); - return (PyObject *)po; -} - -static PyObject *PyCurses_update_panels(PyObject *self) -{ - PyCursesInitialised; - update_panels(); - Py_INCREF(Py_None); - return Py_None; -} - - -/* List of functions defined in the module */ - -static PyMethodDef PyCurses_methods[] = { - {"bottom_panel", (PyCFunction)PyCurses_bottom_panel, METH_NOARGS}, - {"new_panel", (PyCFunction)PyCurses_new_panel, METH_VARARGS}, - {"top_panel", (PyCFunction)PyCurses_top_panel, METH_NOARGS}, - {"update_panels", (PyCFunction)PyCurses_update_panels, METH_NOARGS}, - {NULL, NULL} /* sentinel */ -}; - -/* Initialization function for the module */ - - -static struct PyModuleDef _curses_panelmodule = { - PyModuleDef_HEAD_INIT, - "_curses_panel", - NULL, - sizeof(_curses_panelstate), - PyCurses_methods, - NULL, - _curses_panel_traverse, - _curses_panel_clear, - _curses_panel_free -}; - -PyMODINIT_FUNC -PyInit__curses_panel(void) -{ - PyObject *m, *d, *v; - - /* Create the module and add the functions */ - m = PyModule_Create(&_curses_panelmodule); - if (m == NULL) - goto fail; - d = PyModule_GetDict(m); - - /* Initialize object type */ - v = PyType_FromSpec(&PyCursesPanel_Type_spec); - if (v == NULL) - goto fail; - ((PyTypeObject *)v)->tp_new = NULL; - _curses_panelstate(m)->PyCursesPanel_Type = v; - - import_curses(); - if (PyErr_Occurred()) - goto fail; - - /* For exception _curses_panel.error */ - _curses_panelstate(m)->PyCursesError = PyErr_NewException("_curses_panel.error", NULL, NULL); - PyDict_SetItemString(d, "error", _curses_panelstate(m)->PyCursesError); - - /* Make the version available */ - v = PyUnicode_FromString(PyCursesVersion); - PyDict_SetItemString(d, "version", v); - PyDict_SetItemString(d, "__version__", v); - Py_DECREF(v); - return m; - fail: - Py_XDECREF(m); - return NULL; -} diff --git a/third_party/python/Modules/_cursesmodule.c b/third_party/python/Modules/_cursesmodule.c deleted file mode 100644 index db787fc85..000000000 --- a/third_party/python/Modules/_cursesmodule.c +++ /dev/null @@ -1,3522 +0,0 @@ -/* clang-format off */ -/* - * This is a curses module for Python. - * - * Based on prior work by Lance Ellinghaus and Oliver Andrich - * Version 1.2 of this module: Copyright 1994 by Lance Ellinghouse, - * Cathedral City, California Republic, United States of America. - * - * Version 1.5b1, heavily extended for ncurses by Oliver Andrich: - * Copyright 1996,1997 by Oliver Andrich, Koblenz, Germany. - * - * Tidied for Python 1.6, and currently maintained by . - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this source file to use, copy, modify, merge, or publish it - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or in any new file that contains a substantial portion of - * this file. - * - * THE AUTHOR MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF - * THE SOFTWARE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT - * EXPRESS OR IMPLIED WARRANTY. THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NON-INFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE - * AUTHOR BE LIABLE TO YOU OR ANY OTHER PARTY FOR ANY SPECIAL, - * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER - * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE, STRICT LIABILITY OR - * ANY OTHER ACTION ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. - */ - -/* - - A number of SysV or ncurses functions don't have wrappers yet; if you - need a given function, add it and send a patch. See - http://www.python.org/dev/patches/ for instructions on how to submit - patches to Python. - - Here's a list of currently unsupported functions: - - addchnstr addchstr color_set define_key - del_curterm delscreen dupwin inchnstr inchstr innstr keyok - mcprint mvaddchnstr mvaddchstr mvcur mvinchnstr - mvinchstr mvinnstr mmvwaddchnstr mvwaddchstr - mvwinchnstr mvwinchstr mvwinnstr newterm - restartterm ripoffline scr_dump - scr_init scr_restore scr_set scrl set_curterm set_term setterm - tgetent tgetflag tgetnum tgetstr tgoto timeout tputs - vidattr vidputs waddchnstr waddchstr - wcolor_set winchnstr winchstr winnstr wmouse_trafo wscrl - - Low-priority: - slk_attr slk_attr_off slk_attr_on slk_attr_set slk_attroff - slk_attron slk_attrset slk_clear slk_color slk_init slk_label - slk_noutrefresh slk_refresh slk_restore slk_set slk_touch - - Menu extension (ncurses and probably SYSV): - current_item free_item free_menu item_count item_description - item_index item_init item_name item_opts item_opts_off - item_opts_on item_term item_userptr item_value item_visible - menu_back menu_driver menu_fore menu_format menu_grey - menu_init menu_items menu_mark menu_opts menu_opts_off - menu_opts_on menu_pad menu_pattern menu_request_by_name - menu_request_name menu_spacing menu_sub menu_term menu_userptr - menu_win new_item new_menu pos_menu_cursor post_menu - scale_menu set_current_item set_item_init set_item_opts - set_item_term set_item_userptr set_item_value set_menu_back - set_menu_fore set_menu_format set_menu_grey set_menu_init - set_menu_items set_menu_mark set_menu_opts set_menu_pad - set_menu_pattern set_menu_spacing set_menu_sub set_menu_term - set_menu_userptr set_menu_win set_top_row top_row unpost_menu - - Form extension (ncurses and probably SYSV): - current_field data_ahead data_behind dup_field - dynamic_fieldinfo field_arg field_back field_buffer - field_count field_fore field_index field_info field_init - field_just field_opts field_opts_off field_opts_on field_pad - field_status field_term field_type field_userptr form_driver - form_fields form_init form_opts form_opts_off form_opts_on - form_page form_request_by_name form_request_name form_sub - form_term form_userptr form_win free_field free_form - link_field link_fieldtype move_field new_field new_form - new_page pos_form_cursor post_form scale_form - set_current_field set_field_back set_field_buffer - set_field_fore set_field_init set_field_just set_field_opts - set_field_pad set_field_status set_field_term set_field_type - set_field_userptr set_fieldtype_arg set_fieldtype_choice - set_form_fields set_form_init set_form_opts set_form_page - set_form_sub set_form_term set_form_userptr set_form_win - set_max_field set_new_page unpost_form - - -*/ - -/* Release Number */ - -char *PyCursesVersion = "2.2"; - -/* Includes */ - -#define PY_SSIZE_T_CLEAN - -#include "third_party/python/Include/Python.h" - - -#ifdef __hpux -#define STRICT_SYSV_CURSES -#endif - -#define CURSES_MODULE -#include "third_party/python/Include/py_curses.h" - -#if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5)) -#define STRICT_SYSV_CURSES /* Don't use ncurses extensions */ -typedef chtype attr_t; /* No attr_t type is available */ -#endif - -#if defined(_AIX) -#define STRICT_SYSV_CURSES -#endif - -/*[clinic input] -module curses -class curses.window "PyCursesWindowObject *" "&PyCursesWindow_Type" -[clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=88c860abdbb50e0c]*/ - -#include "third_party/python/Modules/clinic/_cursesmodule.inc" - -/* Definition of exception curses.error */ - -static PyObject *PyCursesError; - -/* Tells whether setupterm() has been called to initialise terminfo. */ -static int initialised_setupterm = FALSE; - -/* Tells whether initscr() has been called to initialise curses. */ -static int initialised = FALSE; - -/* Tells whether start_color() has been called to initialise color usage. */ -static int initialisedcolors = FALSE; - -static char *screen_encoding = NULL; - -/* Utility Macros */ -#define PyCursesSetupTermCalled \ - if (initialised_setupterm != TRUE) { \ - PyErr_SetString(PyCursesError, \ - "must call (at least) setupterm() first"); \ - return 0; } - -#define PyCursesInitialised \ - if (initialised != TRUE) { \ - PyErr_SetString(PyCursesError, \ - "must call initscr() first"); \ - return 0; } - -#define PyCursesInitialisedColor \ - if (initialisedcolors != TRUE) { \ - PyErr_SetString(PyCursesError, \ - "must call start_color() first"); \ - return 0; } - -/* Utility Functions */ - -/* - * Check the return code from a curses function and return None - * or raise an exception as appropriate. These are exported using the - * capsule API. - */ - -static PyObject * -PyCursesCheckERR(int code, const char *fname) -{ - if (code != ERR) { - Py_INCREF(Py_None); - return Py_None; - } else { - if (fname == NULL) { - PyErr_SetString(PyCursesError, catchall_ERR); - } else { - PyErr_Format(PyCursesError, "%s() returned ERR", fname); - } - return NULL; - } -} - -/* Convert an object to a byte (an integer of type chtype): - - - int - - bytes of length 1 - - str of length 1 - - Return 1 on success, 0 on error (invalid type or integer overflow). */ -static int -PyCurses_ConvertToChtype(PyCursesWindowObject *win, PyObject *obj, chtype *ch) -{ - long value; - if(PyBytes_Check(obj) && PyBytes_Size(obj) == 1) { - value = (unsigned char)PyBytes_AsString(obj)[0]; - } - else if (PyUnicode_Check(obj)) { - if (PyUnicode_GetLength(obj) != 1) { - PyErr_Format(PyExc_TypeError, - "expect bytes or str of length 1, or int, " - "got a str of length %zi", - PyUnicode_GET_LENGTH(obj)); - return 0; - } - value = PyUnicode_READ_CHAR(obj, 0); - if (128 < value) { - PyObject *bytes; - const char *encoding; - if (win) - encoding = win->encoding; - else - encoding = screen_encoding; - bytes = PyUnicode_AsEncodedString(obj, encoding, NULL); - if (bytes == NULL) - return 0; - if (PyBytes_GET_SIZE(bytes) == 1) - value = (unsigned char)PyBytes_AS_STRING(bytes)[0]; - else - value = -1; - Py_DECREF(bytes); - if (value < 0) - goto overflow; - } - } - else if (PyLong_CheckExact(obj)) { - int long_overflow; - value = PyLong_AsLongAndOverflow(obj, &long_overflow); - if (long_overflow) - goto overflow; - } - else { - PyErr_Format(PyExc_TypeError, - "expect bytes or str of length 1, or int, got %s", - Py_TYPE(obj)->tp_name); - return 0; - } - *ch = (chtype)value; - if ((long)*ch != value) - goto overflow; - return 1; - -overflow: - PyErr_SetString(PyExc_OverflowError, - "byte doesn't fit in chtype"); - return 0; -} - -/* Convert an object to a byte (chtype) or a character (cchar_t): - - - int - - bytes of length 1 - - str of length 1 - - Return: - - - 2 if obj is a character (written into *wch) - - 1 if obj is a byte (written into *ch) - - 0 on error: raise an exception */ -static int -PyCurses_ConvertToCchar_t(PyCursesWindowObject *win, PyObject *obj, - chtype *ch -#ifdef HAVE_NCURSESW - , wchar_t *wch -#endif - ) -{ - long value; -#ifdef HAVE_NCURSESW - wchar_t buffer[2]; -#endif - - if (PyUnicode_Check(obj)) { -#ifdef HAVE_NCURSESW - if (PyUnicode_AsWideChar(obj, buffer, 2) != 1) { - PyErr_Format(PyExc_TypeError, - "expect bytes or str of length 1, or int, " - "got a str of length %zi", - PyUnicode_GET_LENGTH(obj)); - return 0; - } - *wch = buffer[0]; - return 2; -#else - return PyCurses_ConvertToChtype(win, obj, ch); -#endif - } - else if(PyBytes_Check(obj) && PyBytes_Size(obj) == 1) { - value = (unsigned char)PyBytes_AsString(obj)[0]; - } - else if (PyLong_CheckExact(obj)) { - int overflow; - value = PyLong_AsLongAndOverflow(obj, &overflow); - if (overflow) { - PyErr_SetString(PyExc_OverflowError, - "int doesn't fit in long"); - return 0; - } - } - else { - PyErr_Format(PyExc_TypeError, - "expect bytes or str of length 1, or int, got %s", - Py_TYPE(obj)->tp_name); - return 0; - } - - *ch = (chtype)value; - if ((long)*ch != value) { - PyErr_Format(PyExc_OverflowError, - "byte doesn't fit in chtype"); - return 0; - } - return 1; -} - -/* Convert an object to a byte string (char*) or a wide character string - (wchar_t*). Return: - - - 2 if obj is a character string (written into *wch) - - 1 if obj is a byte string (written into *bytes) - - 0 on error: raise an exception */ -static int -PyCurses_ConvertToString(PyCursesWindowObject *win, PyObject *obj, - PyObject **bytes, wchar_t **wstr) -{ - char *str; - if (PyUnicode_Check(obj)) { -#ifdef HAVE_NCURSESW - assert (wstr != NULL); - *wstr = _PyUnicode_AsWideCharString(obj); - if (*wstr == NULL) - return 0; - return 2; -#else - assert (wstr == NULL); - *bytes = PyUnicode_AsEncodedString(obj, win->encoding, NULL); - if (*bytes == NULL) - return 0; - /* check for embedded null bytes */ - if (PyBytes_AsStringAndSize(*bytes, &str, NULL) < 0) { - return 0; - } - return 1; -#endif - } - else if (PyBytes_Check(obj)) { - Py_INCREF(obj); - *bytes = obj; - /* check for embedded null bytes */ - if (PyBytes_AsStringAndSize(*bytes, &str, NULL) < 0) { - return 0; - } - return 1; - } - - PyErr_Format(PyExc_TypeError, "expect bytes or str, got %s", - Py_TYPE(obj)->tp_name); - return 0; -} - -/* Function versions of the 3 functions for testing whether curses has been - initialised or not. */ - -static int func_PyCursesSetupTermCalled(void) -{ - PyCursesSetupTermCalled; - return 1; -} - -static int func_PyCursesInitialised(void) -{ - PyCursesInitialised; - return 1; -} - -static int func_PyCursesInitialisedColor(void) -{ - PyCursesInitialisedColor; - return 1; -} - -/***************************************************************************** - The Window Object -******************************************************************************/ - -/* Definition of the window type */ - -PyTypeObject PyCursesWindow_Type; - -/* Function prototype macros for Window object - - X - function name - TYPE - parameter Type - ERGSTR - format string for construction of the return value - PARSESTR - format string for argument parsing -*/ - -#define Window_NoArgNoReturnFunction(X) \ - static PyObject *PyCursesWindow_ ## X \ - (PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored)) \ - { return PyCursesCheckERR(X(self->win), # X); } - -#define Window_NoArgTrueFalseFunction(X) \ - static PyObject * PyCursesWindow_ ## X \ - (PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored)) \ - { \ - if (X (self->win) == FALSE) { Py_INCREF(Py_False); return Py_False; } \ - else { Py_INCREF(Py_True); return Py_True; } } - -#define Window_NoArgNoReturnVoidFunction(X) \ - static PyObject * PyCursesWindow_ ## X \ - (PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored)) \ - { \ - X(self->win); Py_INCREF(Py_None); return Py_None; } - -#define Window_NoArg2TupleReturnFunction(X, TYPE, ERGSTR) \ - static PyObject * PyCursesWindow_ ## X \ - (PyCursesWindowObject *self, PyObject *Py_UNUSED(ignored)) \ - { \ - TYPE arg1, arg2; \ - X(self->win,arg1,arg2); return Py_BuildValue(ERGSTR, arg1, arg2); } - -#define Window_OneArgNoReturnVoidFunction(X, TYPE, PARSESTR) \ - static PyObject * PyCursesWindow_ ## X \ - (PyCursesWindowObject *self, PyObject *args) \ - { \ - TYPE arg1; \ - if (!PyArg_ParseTuple(args, PARSESTR, &arg1)) return NULL; \ - X(self->win,arg1); Py_INCREF(Py_None); return Py_None; } - -#define Window_OneArgNoReturnFunction(X, TYPE, PARSESTR) \ - static PyObject * PyCursesWindow_ ## X \ - (PyCursesWindowObject *self, PyObject *args) \ - { \ - TYPE arg1; \ - if (!PyArg_ParseTuple(args,PARSESTR, &arg1)) return NULL; \ - return PyCursesCheckERR(X(self->win, arg1), # X); } - -#define Window_TwoArgNoReturnFunction(X, TYPE, PARSESTR) \ - static PyObject * PyCursesWindow_ ## X \ - (PyCursesWindowObject *self, PyObject *args) \ - { \ - TYPE arg1, arg2; \ - if (!PyArg_ParseTuple(args,PARSESTR, &arg1, &arg2)) return NULL; \ - return PyCursesCheckERR(X(self->win, arg1, arg2), # X); } - -/* ------------- WINDOW routines --------------- */ - -Window_NoArgNoReturnFunction(untouchwin) -Window_NoArgNoReturnFunction(touchwin) -Window_NoArgNoReturnFunction(redrawwin) -Window_NoArgNoReturnFunction(winsertln) -Window_NoArgNoReturnFunction(werase) -Window_NoArgNoReturnFunction(wdeleteln) - -Window_NoArgTrueFalseFunction(is_wintouched) - -Window_NoArgNoReturnVoidFunction(wsyncup) -Window_NoArgNoReturnVoidFunction(wsyncdown) -Window_NoArgNoReturnVoidFunction(wstandend) -Window_NoArgNoReturnVoidFunction(wstandout) -Window_NoArgNoReturnVoidFunction(wcursyncup) -Window_NoArgNoReturnVoidFunction(wclrtoeol) -Window_NoArgNoReturnVoidFunction(wclrtobot) -Window_NoArgNoReturnVoidFunction(wclear) - -Window_OneArgNoReturnVoidFunction(idcok, int, "i;True(1) or False(0)") -#ifdef HAVE_CURSES_IMMEDOK -Window_OneArgNoReturnVoidFunction(immedok, int, "i;True(1) or False(0)") -#endif -Window_OneArgNoReturnVoidFunction(wtimeout, int, "i;delay") - -Window_NoArg2TupleReturnFunction(getyx, int, "ii") -Window_NoArg2TupleReturnFunction(getbegyx, int, "ii") -Window_NoArg2TupleReturnFunction(getmaxyx, int, "ii") -Window_NoArg2TupleReturnFunction(getparyx, int, "ii") - -Window_OneArgNoReturnFunction(clearok, int, "i;True(1) or False(0)") -Window_OneArgNoReturnFunction(idlok, int, "i;True(1) or False(0)") -Window_OneArgNoReturnFunction(keypad, int, "i;True(1) or False(0)") -Window_OneArgNoReturnFunction(leaveok, int, "i;True(1) or False(0)") -Window_OneArgNoReturnFunction(nodelay, int, "i;True(1) or False(0)") -Window_OneArgNoReturnFunction(notimeout, int, "i;True(1) or False(0)") -Window_OneArgNoReturnFunction(scrollok, int, "i;True(1) or False(0)") -Window_OneArgNoReturnFunction(winsdelln, int, "i;nlines") -#ifdef HAVE_CURSES_SYNCOK -Window_OneArgNoReturnFunction(syncok, int, "i;True(1) or False(0)") -#endif - -Window_TwoArgNoReturnFunction(mvwin, int, "ii;y,x") -Window_TwoArgNoReturnFunction(mvderwin, int, "ii;y,x") -Window_TwoArgNoReturnFunction(wmove, int, "ii;y,x") -#ifndef STRICT_SYSV_CURSES -Window_TwoArgNoReturnFunction(wresize, int, "ii;lines,columns") -#endif - -/* Allocation and deallocation of Window Objects */ - -static PyObject * -PyCursesWindow_New(WINDOW *win, const char *encoding) -{ - PyCursesWindowObject *wo; - - if (encoding == NULL) { -#if defined(MS_WINDOWS) - char *buffer[100]; - UINT cp; - cp = GetConsoleOutputCP(); - if (cp != 0) { - PyOS_snprintf(buffer, sizeof(buffer), "cp%u", cp); - encoding = buffer; - } -#elif defined(CODESET) - const char *codeset = nl_langinfo(CODESET); - if (codeset != NULL && codeset[0] != 0) - encoding = codeset; -#endif - if (encoding == NULL) - encoding = "utf-8"; - } - - wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type); - if (wo == NULL) return NULL; - wo->win = win; - wo->encoding = _PyMem_Strdup(encoding); - if (wo->encoding == NULL) { - Py_DECREF(wo); - PyErr_NoMemory(); - return NULL; - } - return (PyObject *)wo; -} - -static void -PyCursesWindow_Dealloc(PyCursesWindowObject *wo) -{ - if (wo->win != stdscr) delwin(wo->win); - if (wo->encoding != NULL) - PyMem_Free(wo->encoding); - PyObject_DEL(wo); -} - -/* Addch, Addstr, Addnstr */ - -/*[clinic input] - -curses.window.addch - - [ - y: int - Y-coordinate. - x: int - X-coordinate. - ] - - ch: object - Character to add. - - [ - attr: long - Attributes for the character. - ] - / - -Paint character ch at (y, x) with attributes attr. - -Paint character ch at (y, x) with attributes attr, -overwriting any character previously painted at that location. -By default, the character position and attributes are the -current settings for the window object. -[clinic start generated code]*/ - -static PyObject * -curses_window_addch_impl(PyCursesWindowObject *self, int group_left_1, int y, - int x, PyObject *ch, int group_right_1, long attr) -/*[clinic end generated code: output=99f7f85078ec06c3 input=5a41efb34a2de338]*/ -{ - PyCursesWindowObject *cwself = (PyCursesWindowObject *)self; - int coordinates_group = group_left_1; - int attr_group = group_right_1; - int rtn; - int type; - chtype cch; -#ifdef HAVE_NCURSESW - wchar_t wstr[2]; - cchar_t wcval; -#endif - const char *funcname; - - if (!attr_group) - attr = A_NORMAL; - -#ifdef HAVE_NCURSESW - type = PyCurses_ConvertToCchar_t(cwself, ch, &cch, wstr); - if (type == 2) { - funcname = "add_wch"; - wstr[1] = L'\0'; - setcchar(&wcval, wstr, attr, 0, NULL); - if (coordinates_group) - rtn = mvwadd_wch(cwself->win,y,x, &wcval); - else { - rtn = wadd_wch(cwself->win, &wcval); - } - } - else -#else - type = PyCurses_ConvertToCchar_t(cwself, ch, &cch); -#endif - if (type == 1) { - funcname = "addch"; - if (coordinates_group) - rtn = mvwaddch(cwself->win,y,x, cch | attr); - else { - rtn = waddch(cwself->win, cch | attr); - } - } - else { - return NULL; - } - return PyCursesCheckERR(rtn, funcname); -} - -static PyObject * -PyCursesWindow_AddStr(PyCursesWindowObject *self, PyObject *args) -{ - int rtn; - int x, y; - int strtype; - PyObject *strobj, *bytesobj = NULL; -#ifdef HAVE_NCURSESW - wchar_t *wstr = NULL; -#endif - attr_t attr = A_NORMAL , attr_old = A_NORMAL; - long lattr; - int use_xy = FALSE, use_attr = FALSE; - const char *funcname; - - switch (PyTuple_Size(args)) { - case 1: - if (!PyArg_ParseTuple(args,"O;str", &strobj)) - return NULL; - break; - case 2: - if (!PyArg_ParseTuple(args,"Ol;str,attr", &strobj, &lattr)) - return NULL; - attr = lattr; - use_attr = TRUE; - break; - case 3: - if (!PyArg_ParseTuple(args,"iiO;int,int,str", &y, &x, &strobj)) - return NULL; - use_xy = TRUE; - break; - case 4: - if (!PyArg_ParseTuple(args,"iiOl;int,int,str,attr", &y, &x, &strobj, &lattr)) - return NULL; - attr = lattr; - use_xy = use_attr = TRUE; - break; - default: - PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments"); - return NULL; - } -#ifdef HAVE_NCURSESW - strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, &wstr); -#else - strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, NULL); -#endif - if (strtype == 0) - return NULL; - if (use_attr == TRUE) { - attr_old = getattrs(self->win); - (void)wattrset(self->win,attr); - } -#ifdef HAVE_NCURSESW - if (strtype == 2) { - funcname = "addwstr"; - if (use_xy == TRUE) - rtn = mvwaddwstr(self->win,y,x,wstr); - else - rtn = waddwstr(self->win,wstr); - PyMem_Free(wstr); - } - else -#endif - { - char *str = PyBytes_AS_STRING(bytesobj); - funcname = "addstr"; - if (use_xy == TRUE) - rtn = mvwaddstr(self->win,y,x,str); - else - rtn = waddstr(self->win,str); - Py_DECREF(bytesobj); - } - if (use_attr == TRUE) - (void)wattrset(self->win,attr_old); - return PyCursesCheckERR(rtn, funcname); -} - -static PyObject * -PyCursesWindow_AddNStr(PyCursesWindowObject *self, PyObject *args) -{ - int rtn, x, y, n; - int strtype; - PyObject *strobj, *bytesobj = NULL; -#ifdef HAVE_NCURSESW - wchar_t *wstr = NULL; -#endif - attr_t attr = A_NORMAL , attr_old = A_NORMAL; - long lattr; - int use_xy = FALSE, use_attr = FALSE; - const char *funcname; - - switch (PyTuple_Size(args)) { - case 2: - if (!PyArg_ParseTuple(args,"Oi;str,n", &strobj, &n)) - return NULL; - break; - case 3: - if (!PyArg_ParseTuple(args,"Oil;str,n,attr", &strobj, &n, &lattr)) - return NULL; - attr = lattr; - use_attr = TRUE; - break; - case 4: - if (!PyArg_ParseTuple(args,"iiOi;y,x,str,n", &y, &x, &strobj, &n)) - return NULL; - use_xy = TRUE; - break; - case 5: - if (!PyArg_ParseTuple(args,"iiOil;y,x,str,n,attr", &y, &x, &strobj, &n, &lattr)) - return NULL; - attr = lattr; - use_xy = use_attr = TRUE; - break; - default: - PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments"); - return NULL; - } -#ifdef HAVE_NCURSESW - strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, &wstr); -#else - strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, NULL); -#endif - if (strtype == 0) - return NULL; - - if (use_attr == TRUE) { - attr_old = getattrs(self->win); - (void)wattrset(self->win,attr); - } -#ifdef HAVE_NCURSESW - if (strtype == 2) { - funcname = "addnwstr"; - if (use_xy == TRUE) - rtn = mvwaddnwstr(self->win,y,x,wstr,n); - else - rtn = waddnwstr(self->win,wstr,n); - PyMem_Free(wstr); - } - else -#endif - { - char *str = PyBytes_AS_STRING(bytesobj); - funcname = "addnstr"; - if (use_xy == TRUE) - rtn = mvwaddnstr(self->win,y,x,str,n); - else - rtn = waddnstr(self->win,str,n); - Py_DECREF(bytesobj); - } - if (use_attr == TRUE) - (void)wattrset(self->win,attr_old); - return PyCursesCheckERR(rtn, funcname); -} - -static PyObject * -PyCursesWindow_Bkgd(PyCursesWindowObject *self, PyObject *args) -{ - PyObject *temp; - chtype bkgd; - attr_t attr = A_NORMAL; - long lattr; - - switch (PyTuple_Size(args)) { - case 1: - if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) - return NULL; - break; - case 2: - if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr)) - return NULL; - attr = lattr; - break; - default: - PyErr_SetString(PyExc_TypeError, "bkgd requires 1 or 2 arguments"); - return NULL; - } - - if (!PyCurses_ConvertToChtype(self, temp, &bkgd)) - return NULL; - - return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd"); -} - -static PyObject * -PyCursesWindow_AttrOff(PyCursesWindowObject *self, PyObject *args) -{ - long lattr; - if (!PyArg_ParseTuple(args,"l;attr", &lattr)) - return NULL; - return PyCursesCheckERR(wattroff(self->win, (attr_t)lattr), "attroff"); -} - -static PyObject * -PyCursesWindow_AttrOn(PyCursesWindowObject *self, PyObject *args) -{ - long lattr; - if (!PyArg_ParseTuple(args,"l;attr", &lattr)) - return NULL; - return PyCursesCheckERR(wattron(self->win, (attr_t)lattr), "attron"); -} - -static PyObject * -PyCursesWindow_AttrSet(PyCursesWindowObject *self, PyObject *args) -{ - long lattr; - if (!PyArg_ParseTuple(args,"l;attr", &lattr)) - return NULL; - return PyCursesCheckERR(wattrset(self->win, (attr_t)lattr), "attrset"); -} - -static PyObject * -PyCursesWindow_BkgdSet(PyCursesWindowObject *self, PyObject *args) -{ - PyObject *temp; - chtype bkgd; - attr_t attr = A_NORMAL; - long lattr; - - switch (PyTuple_Size(args)) { - case 1: - if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) - return NULL; - break; - case 2: - if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr)) - return NULL; - attr = lattr; - break; - default: - PyErr_SetString(PyExc_TypeError, "bkgdset requires 1 or 2 arguments"); - return NULL; - } - - if (!PyCurses_ConvertToChtype(self, temp, &bkgd)) - return NULL; - - wbkgdset(self->win, bkgd | attr); - return PyCursesCheckERR(0, "bkgdset"); -} - -static PyObject * -PyCursesWindow_Border(PyCursesWindowObject *self, PyObject *args) -{ - PyObject *temp[8]; - chtype ch[8]; - int i; - - /* Clear the array of parameters */ - for(i=0; i<8; i++) { - temp[i] = NULL; - ch[i] = 0; - } - - if (!PyArg_ParseTuple(args,"|OOOOOOOO;ls,rs,ts,bs,tl,tr,bl,br", - &temp[0], &temp[1], &temp[2], &temp[3], - &temp[4], &temp[5], &temp[6], &temp[7])) - return NULL; - - for(i=0; i<8; i++) { - if (temp[i] != NULL && !PyCurses_ConvertToChtype(self, temp[i], &ch[i])) - return NULL; - } - - wborder(self->win, - ch[0], ch[1], ch[2], ch[3], - ch[4], ch[5], ch[6], ch[7]); - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject * -PyCursesWindow_Box(PyCursesWindowObject *self, PyObject *args) -{ - PyObject *temp1, *temp2; - chtype ch1=0,ch2=0; - switch(PyTuple_Size(args)){ - case 0: break; - default: - if (!PyArg_ParseTuple(args,"OO;verch,horch", &temp1, &temp2)) - return NULL; - if (!PyCurses_ConvertToChtype(self, temp1, &ch1)) { - return NULL; - } - if (!PyCurses_ConvertToChtype(self, temp2, &ch2)) { - return NULL; - } - } - box(self->win,ch1,ch2); - Py_INCREF(Py_None); - return Py_None; -} - -#if defined(HAVE_NCURSES_H) || defined(MVWDELCH_IS_EXPRESSION) -#define py_mvwdelch mvwdelch -#else -int py_mvwdelch(WINDOW *w, int y, int x) -{ - mvwdelch(w,y,x); - /* On HP/UX, mvwdelch already returns. On other systems, - we may well run into this return statement. */ - return 0; -} -#endif - -#if defined(HAVE_CURSES_IS_PAD) -#define py_is_pad(win) is_pad(win) -#elif defined(WINDOW_HAS_FLAGS) -#define py_is_pad(win) ((win) ? ((win)->_flags & _ISPAD) != 0 : FALSE) -#endif - -/* chgat, added by Fabian Kreutz */ -#ifdef HAVE_CURSES_WCHGAT -static PyObject * -PyCursesWindow_ChgAt(PyCursesWindowObject *self, PyObject *args) -{ - int rtn; - int x, y; - int num = -1; - short color; - attr_t attr = A_NORMAL; - long lattr; - int use_xy = FALSE; - - switch (PyTuple_Size(args)) { - case 1: - if (!PyArg_ParseTuple(args,"l;attr", &lattr)) - return NULL; - attr = lattr; - break; - case 2: - if (!PyArg_ParseTuple(args,"il;n,attr", &num, &lattr)) - return NULL; - attr = lattr; - break; - case 3: - if (!PyArg_ParseTuple(args,"iil;int,int,attr", &y, &x, &lattr)) - return NULL; - attr = lattr; - use_xy = TRUE; - break; - case 4: - if (!PyArg_ParseTuple(args,"iiil;int,int,n,attr", &y, &x, &num, &lattr)) - return NULL; - attr = lattr; - use_xy = TRUE; - break; - default: - PyErr_SetString(PyExc_TypeError, "chgat requires 1 to 4 arguments"); - return NULL; - } - - color = (short)((attr >> 8) & 0xff); - attr = attr - (color << 8); - - if (use_xy == TRUE) { - rtn = mvwchgat(self->win,y,x,num,attr,color,NULL); - touchline(self->win,y,1); - } else { - getyx(self->win,y,x); - rtn = wchgat(self->win,num,attr,color,NULL); - touchline(self->win,y,1); - } - return PyCursesCheckERR(rtn, "chgat"); -} -#endif - -static PyObject * -PyCursesWindow_DelCh(PyCursesWindowObject *self, PyObject *args) -{ - int rtn; - int x, y; - - switch (PyTuple_Size(args)) { - case 0: - rtn = wdelch(self->win); - break; - case 2: - if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x)) - return NULL; - rtn = py_mvwdelch(self->win,y,x); - break; - default: - PyErr_SetString(PyExc_TypeError, "delch requires 0 or 2 arguments"); - return NULL; - } - return PyCursesCheckERR(rtn, "[mv]wdelch"); -} - -static PyObject * -PyCursesWindow_DerWin(PyCursesWindowObject *self, PyObject *args) -{ - WINDOW *win; - int nlines, ncols, begin_y, begin_x; - - nlines = 0; - ncols = 0; - switch (PyTuple_Size(args)) { - case 2: - if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x)) - return NULL; - break; - case 4: - if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x", - &nlines,&ncols,&begin_y,&begin_x)) - return NULL; - break; - default: - PyErr_SetString(PyExc_TypeError, "derwin requires 2 or 4 arguments"); - return NULL; - } - - win = derwin(self->win,nlines,ncols,begin_y,begin_x); - - if (win == NULL) { - PyErr_SetString(PyCursesError, catchall_NULL); - return NULL; - } - - return (PyObject *)PyCursesWindow_New(win, NULL); -} - -static PyObject * -PyCursesWindow_EchoChar(PyCursesWindowObject *self, PyObject *args) -{ - PyObject *temp; - chtype ch; - attr_t attr = A_NORMAL; - long lattr; - - switch (PyTuple_Size(args)) { - case 1: - if (!PyArg_ParseTuple(args,"O;ch or int", &temp)) - return NULL; - break; - case 2: - if (!PyArg_ParseTuple(args,"Ol;ch or int,attr", &temp, &lattr)) - return NULL; - attr = lattr; - break; - default: - PyErr_SetString(PyExc_TypeError, "echochar requires 1 or 2 arguments"); - - - return NULL; - } - - if (!PyCurses_ConvertToChtype(self, temp, &ch)) - return NULL; - -#ifdef py_is_pad - if (py_is_pad(self->win)) { - return PyCursesCheckERR(pechochar(self->win, ch | attr), - "echochar"); - } - else -#endif - return PyCursesCheckERR(wechochar(self->win, ch | attr), - "echochar"); -} - -#ifdef NCURSES_MOUSE_VERSION -static PyObject * -PyCursesWindow_Enclose(PyCursesWindowObject *self, PyObject *args) -{ - int x, y; - if (!PyArg_ParseTuple(args,"ii;y,x", &y, &x)) - return NULL; - - return PyLong_FromLong( wenclose(self->win,y,x) ); -} -#endif - -static PyObject * -PyCursesWindow_GetBkgd(PyCursesWindowObject *self) -{ - return PyLong_FromLong((long) getbkgd(self->win)); -} - -static PyObject * -PyCursesWindow_GetCh(PyCursesWindowObject *self, PyObject *args) -{ - int x, y; - int rtn; - - switch (PyTuple_Size(args)) { - case 0: - Py_BEGIN_ALLOW_THREADS - rtn = wgetch(self->win); - Py_END_ALLOW_THREADS - break; - case 2: - if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) - return NULL; - Py_BEGIN_ALLOW_THREADS - rtn = mvwgetch(self->win,y,x); - Py_END_ALLOW_THREADS - break; - default: - PyErr_SetString(PyExc_TypeError, "getch requires 0 or 2 arguments"); - return NULL; - } - return PyLong_FromLong((long)rtn); -} - -static PyObject * -PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args) -{ - int x, y; - int rtn; - - switch (PyTuple_Size(args)) { - case 0: - Py_BEGIN_ALLOW_THREADS - rtn = wgetch(self->win); - Py_END_ALLOW_THREADS - break; - case 2: - if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) - return NULL; - Py_BEGIN_ALLOW_THREADS - rtn = mvwgetch(self->win,y,x); - Py_END_ALLOW_THREADS - break; - default: - PyErr_SetString(PyExc_TypeError, "getkey requires 0 or 2 arguments"); - return NULL; - } - if (rtn == ERR) { - /* getch() returns ERR in nodelay mode */ - PyErr_CheckSignals(); - if (!PyErr_Occurred()) - PyErr_SetString(PyCursesError, "no input"); - return NULL; - } else if (rtn <= 255) { -#ifdef NCURSES_VERSION_MAJOR -#if NCURSES_VERSION_MAJOR*100+NCURSES_VERSION_MINOR <= 507 - /* Work around a bug in ncurses 5.7 and earlier */ - if (rtn < 0) { - rtn += 256; - } -#endif -#endif - return PyUnicode_FromOrdinal(rtn); - } else { - const char *knp = keyname(rtn); - return PyUnicode_FromString((knp == NULL) ? "" : knp); - } -} - -#ifdef HAVE_NCURSESW -static PyObject * -PyCursesWindow_Get_WCh(PyCursesWindowObject *self, PyObject *args) -{ - int x, y; - int ct; - wint_t rtn; - - switch (PyTuple_Size(args)) { - case 0: - Py_BEGIN_ALLOW_THREADS - ct = wget_wch(self->win,&rtn); - Py_END_ALLOW_THREADS - break; - case 2: - if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) - return NULL; - Py_BEGIN_ALLOW_THREADS - ct = mvwget_wch(self->win,y,x,&rtn); - Py_END_ALLOW_THREADS - break; - default: - PyErr_SetString(PyExc_TypeError, "get_wch requires 0 or 2 arguments"); - return NULL; - } - if (ct == ERR) { - if (PyErr_CheckSignals()) - return NULL; - - /* get_wch() returns ERR in nodelay mode */ - PyErr_SetString(PyCursesError, "no input"); - return NULL; - } - if (ct == KEY_CODE_YES) - return PyLong_FromLong(rtn); - else - return PyUnicode_FromOrdinal(rtn); -} -#endif - -static PyObject * -PyCursesWindow_GetStr(PyCursesWindowObject *self, PyObject *args) -{ - int x, y, n; - char rtn[1024]; /* This should be big enough.. I hope */ - int rtn2; - - switch (PyTuple_Size(args)) { - case 0: - Py_BEGIN_ALLOW_THREADS - rtn2 = wgetnstr(self->win,rtn, 1023); - Py_END_ALLOW_THREADS - break; - case 1: - if (!PyArg_ParseTuple(args,"i;n", &n)) - return NULL; - if (n < 0) { - PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative"); - return NULL; - } - Py_BEGIN_ALLOW_THREADS - rtn2 = wgetnstr(self->win, rtn, Py_MIN(n, 1023)); - Py_END_ALLOW_THREADS - break; - case 2: - if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) - return NULL; - Py_BEGIN_ALLOW_THREADS -#ifdef STRICT_SYSV_CURSES - rtn2 = wmove(self->win,y,x)==ERR ? ERR : wgetnstr(self->win, rtn, 1023); -#else - rtn2 = mvwgetnstr(self->win,y,x,rtn, 1023); -#endif - Py_END_ALLOW_THREADS - break; - case 3: - if (!PyArg_ParseTuple(args,"iii;y,x,n", &y, &x, &n)) - return NULL; - if (n < 0) { - PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative"); - return NULL; - } -#ifdef STRICT_SYSV_CURSES - Py_BEGIN_ALLOW_THREADS - rtn2 = wmove(self->win,y,x)==ERR ? ERR : - wgetnstr(self->win, rtn, Py_MIN(n, 1023)); - Py_END_ALLOW_THREADS -#else - Py_BEGIN_ALLOW_THREADS - rtn2 = mvwgetnstr(self->win, y, x, rtn, Py_MIN(n, 1023)); - Py_END_ALLOW_THREADS -#endif - break; - default: - PyErr_SetString(PyExc_TypeError, "getstr requires 0 to 3 arguments"); - return NULL; - } - if (rtn2 == ERR) - rtn[0] = 0; - return PyBytes_FromString(rtn); -} - -static PyObject * -PyCursesWindow_Hline(PyCursesWindowObject *self, PyObject *args) -{ - PyObject *temp; - chtype ch; - int n, x, y, code = OK; - attr_t attr = A_NORMAL; - long lattr; - - switch (PyTuple_Size(args)) { - case 2: - if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n)) - return NULL; - break; - case 3: - if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr)) - return NULL; - attr = lattr; - break; - case 4: - if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n)) - return NULL; - code = wmove(self->win, y, x); - break; - case 5: - if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr", - &y, &x, &temp, &n, &lattr)) - return NULL; - attr = lattr; - code = wmove(self->win, y, x); - break; - default: - PyErr_SetString(PyExc_TypeError, "hline requires 2 to 5 arguments"); - return NULL; - } - - if (code != ERR) { - if (!PyCurses_ConvertToChtype(self, temp, &ch)) - return NULL; - return PyCursesCheckERR(whline(self->win, ch | attr, n), "hline"); - } else - return PyCursesCheckERR(code, "wmove"); -} - -static PyObject * -PyCursesWindow_InsCh(PyCursesWindowObject *self, PyObject *args) -{ - int rtn, x, y, use_xy = FALSE; - PyObject *temp; - chtype ch = 0; - attr_t attr = A_NORMAL; - long lattr; - - switch (PyTuple_Size(args)) { - case 1: - if (!PyArg_ParseTuple(args, "O;ch or int", &temp)) - return NULL; - break; - case 2: - if (!PyArg_ParseTuple(args, "Ol;ch or int,attr", &temp, &lattr)) - return NULL; - attr = lattr; - break; - case 3: - if (!PyArg_ParseTuple(args,"iiO;y,x,ch or int", &y, &x, &temp)) - return NULL; - use_xy = TRUE; - break; - case 4: - if (!PyArg_ParseTuple(args,"iiOl;y,x,ch or int, attr", &y, &x, &temp, &lattr)) - return NULL; - attr = lattr; - use_xy = TRUE; - break; - default: - PyErr_SetString(PyExc_TypeError, "insch requires 1 to 4 arguments"); - return NULL; - } - - if (!PyCurses_ConvertToChtype(self, temp, &ch)) - return NULL; - - if (use_xy == TRUE) - rtn = mvwinsch(self->win,y,x, ch | attr); - else { - rtn = winsch(self->win, ch | attr); - } - return PyCursesCheckERR(rtn, "insch"); -} - -static PyObject * -PyCursesWindow_InCh(PyCursesWindowObject *self, PyObject *args) -{ - int x, y; - unsigned long rtn; - - switch (PyTuple_Size(args)) { - case 0: - rtn = winch(self->win); - break; - case 2: - if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) - return NULL; - rtn = mvwinch(self->win,y,x); - break; - default: - PyErr_SetString(PyExc_TypeError, "inch requires 0 to 2 arguments"); - return NULL; - } - return PyLong_FromUnsignedLong(rtn); -} - -static PyObject * -PyCursesWindow_InStr(PyCursesWindowObject *self, PyObject *args) -{ - int x, y, n; - char rtn[1024]; /* This should be big enough.. I hope */ - int rtn2; - - switch (PyTuple_Size(args)) { - case 0: - rtn2 = winnstr(self->win,rtn, 1023); - break; - case 1: - if (!PyArg_ParseTuple(args,"i;n", &n)) - return NULL; - if (n < 0) { - PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative"); - return NULL; - } - rtn2 = winnstr(self->win, rtn, Py_MIN(n, 1023)); - break; - case 2: - if (!PyArg_ParseTuple(args,"ii;y,x",&y,&x)) - return NULL; - rtn2 = mvwinnstr(self->win,y,x,rtn,1023); - break; - case 3: - if (!PyArg_ParseTuple(args, "iii;y,x,n", &y, &x, &n)) - return NULL; - if (n < 0) { - PyErr_SetString(PyExc_ValueError, "'n' must be nonnegative"); - return NULL; - } - rtn2 = mvwinnstr(self->win, y, x, rtn, Py_MIN(n,1023)); - break; - default: - PyErr_SetString(PyExc_TypeError, "instr requires 0 or 3 arguments"); - return NULL; - } - if (rtn2 == ERR) - rtn[0] = 0; - return PyBytes_FromString(rtn); -} - -static PyObject * -PyCursesWindow_InsStr(PyCursesWindowObject *self, PyObject *args) -{ - int rtn; - int x, y; - int strtype; - PyObject *strobj, *bytesobj = NULL; -#ifdef HAVE_NCURSESW - wchar_t *wstr = NULL; -#endif - attr_t attr = A_NORMAL , attr_old = A_NORMAL; - long lattr; - int use_xy = FALSE, use_attr = FALSE; - const char *funcname; - - switch (PyTuple_Size(args)) { - case 1: - if (!PyArg_ParseTuple(args,"O;str", &strobj)) - return NULL; - break; - case 2: - if (!PyArg_ParseTuple(args,"Ol;str,attr", &strobj, &lattr)) - return NULL; - attr = lattr; - use_attr = TRUE; - break; - case 3: - if (!PyArg_ParseTuple(args,"iiO;y,x,str", &y, &x, &strobj)) - return NULL; - use_xy = TRUE; - break; - case 4: - if (!PyArg_ParseTuple(args,"iiOl;y,x,str,attr", &y, &x, &strobj, &lattr)) - return NULL; - attr = lattr; - use_xy = use_attr = TRUE; - break; - default: - PyErr_SetString(PyExc_TypeError, "insstr requires 1 to 4 arguments"); - return NULL; - } - -#ifdef HAVE_NCURSESW - strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, &wstr); -#else - strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, NULL); -#endif - if (strtype == 0) - return NULL; - - if (use_attr == TRUE) { - attr_old = getattrs(self->win); - (void)wattrset(self->win,attr); - } -#ifdef HAVE_NCURSESW - if (strtype == 2) { - funcname = "inswstr"; - if (use_xy == TRUE) - rtn = mvwins_wstr(self->win,y,x,wstr); - else - rtn = wins_wstr(self->win,wstr); - PyMem_Free(wstr); - } - else -#endif - { - char *str = PyBytes_AS_STRING(bytesobj); - funcname = "insstr"; - if (use_xy == TRUE) - rtn = mvwinsstr(self->win,y,x,str); - else - rtn = winsstr(self->win,str); - Py_DECREF(bytesobj); - } - if (use_attr == TRUE) - (void)wattrset(self->win,attr_old); - return PyCursesCheckERR(rtn, funcname); -} - -static PyObject * -PyCursesWindow_InsNStr(PyCursesWindowObject *self, PyObject *args) -{ - int rtn, x, y, n; - int strtype; - PyObject *strobj, *bytesobj = NULL; -#ifdef HAVE_NCURSESW - wchar_t *wstr = NULL; -#endif - attr_t attr = A_NORMAL , attr_old = A_NORMAL; - long lattr; - int use_xy = FALSE, use_attr = FALSE; - const char *funcname; - - switch (PyTuple_Size(args)) { - case 2: - if (!PyArg_ParseTuple(args,"Oi;str,n", &strobj, &n)) - return NULL; - break; - case 3: - if (!PyArg_ParseTuple(args,"Oil;str,n,attr", &strobj, &n, &lattr)) - return NULL; - attr = lattr; - use_attr = TRUE; - break; - case 4: - if (!PyArg_ParseTuple(args,"iiOi;y,x,str,n", &y, &x, &strobj, &n)) - return NULL; - use_xy = TRUE; - break; - case 5: - if (!PyArg_ParseTuple(args,"iiOil;y,x,str,n,attr", &y, &x, &strobj, &n, &lattr)) - return NULL; - attr = lattr; - use_xy = use_attr = TRUE; - break; - default: - PyErr_SetString(PyExc_TypeError, "insnstr requires 2 to 5 arguments"); - return NULL; - } - -#ifdef HAVE_NCURSESW - strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, &wstr); -#else - strtype = PyCurses_ConvertToString(self, strobj, &bytesobj, NULL); -#endif - if (strtype == 0) - return NULL; - - if (use_attr == TRUE) { - attr_old = getattrs(self->win); - (void)wattrset(self->win,attr); - } -#ifdef HAVE_NCURSESW - if (strtype == 2) { - funcname = "insn_wstr"; - if (use_xy == TRUE) - rtn = mvwins_nwstr(self->win,y,x,wstr,n); - else - rtn = wins_nwstr(self->win,wstr,n); - PyMem_Free(wstr); - } - else -#endif - { - char *str = PyBytes_AS_STRING(bytesobj); - funcname = "insnstr"; - if (use_xy == TRUE) - rtn = mvwinsnstr(self->win,y,x,str,n); - else - rtn = winsnstr(self->win,str,n); - Py_DECREF(bytesobj); - } - if (use_attr == TRUE) - (void)wattrset(self->win,attr_old); - return PyCursesCheckERR(rtn, funcname); -} - -static PyObject * -PyCursesWindow_Is_LineTouched(PyCursesWindowObject *self, PyObject *args) -{ - int line, erg; - if (!PyArg_ParseTuple(args,"i;line", &line)) - return NULL; - erg = is_linetouched(self->win, line); - if (erg == ERR) { - PyErr_SetString(PyExc_TypeError, - "is_linetouched: line number outside of boundaries"); - return NULL; - } else - if (erg == FALSE) { - Py_INCREF(Py_False); - return Py_False; - } else { - Py_INCREF(Py_True); - return Py_True; - } -} - -static PyObject * -PyCursesWindow_NoOutRefresh(PyCursesWindowObject *self, PyObject *args) -{ - int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol; - int rtn; - -#ifndef py_is_pad - if (0) -#else - if (py_is_pad(self->win)) -#endif - { - switch(PyTuple_Size(args)) { - case 6: - if (!PyArg_ParseTuple(args, - "iiiiii;" \ - "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol", - &pminrow, &pmincol, &sminrow, - &smincol, &smaxrow, &smaxcol)) - return NULL; - Py_BEGIN_ALLOW_THREADS - rtn = pnoutrefresh(self->win, - pminrow, pmincol, sminrow, - smincol, smaxrow, smaxcol); - Py_END_ALLOW_THREADS - return PyCursesCheckERR(rtn, "pnoutrefresh"); - default: - PyErr_SetString(PyCursesError, - "noutrefresh() called for a pad " - "requires 6 arguments"); - return NULL; - } - } else { - if (!PyArg_ParseTuple(args, ":noutrefresh")) - return NULL; - - Py_BEGIN_ALLOW_THREADS - rtn = wnoutrefresh(self->win); - Py_END_ALLOW_THREADS - return PyCursesCheckERR(rtn, "wnoutrefresh"); - } -} - -static PyObject * -PyCursesWindow_Overlay(PyCursesWindowObject *self, PyObject *args) -{ - PyCursesWindowObject *temp; - int use_copywin = FALSE; - int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol; - int rtn; - - switch (PyTuple_Size(args)) { - case 1: - if (!PyArg_ParseTuple(args, "O!;window object", - &PyCursesWindow_Type, &temp)) - return NULL; - break; - case 7: - if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int", - &PyCursesWindow_Type, &temp, &sminrow, &smincol, - &dminrow, &dmincol, &dmaxrow, &dmaxcol)) - return NULL; - use_copywin = TRUE; - break; - default: - PyErr_SetString(PyExc_TypeError, - "overlay requires one or seven arguments"); - return NULL; - } - - if (use_copywin == TRUE) { - rtn = copywin(self->win, temp->win, sminrow, smincol, - dminrow, dmincol, dmaxrow, dmaxcol, TRUE); - return PyCursesCheckERR(rtn, "copywin"); - } - else { - rtn = overlay(self->win, temp->win); - return PyCursesCheckERR(rtn, "overlay"); - } -} - -static PyObject * -PyCursesWindow_Overwrite(PyCursesWindowObject *self, PyObject *args) -{ - PyCursesWindowObject *temp; - int use_copywin = FALSE; - int sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol; - int rtn; - - switch (PyTuple_Size(args)) { - case 1: - if (!PyArg_ParseTuple(args, "O!;window object", - &PyCursesWindow_Type, &temp)) - return NULL; - break; - case 7: - if (!PyArg_ParseTuple(args, "O!iiiiii;window object, int, int, int, int, int, int", - &PyCursesWindow_Type, &temp, &sminrow, &smincol, - &dminrow, &dmincol, &dmaxrow, &dmaxcol)) - return NULL; - use_copywin = TRUE; - break; - default: - PyErr_SetString(PyExc_TypeError, - "overwrite requires one or seven arguments"); - return NULL; - } - - if (use_copywin == TRUE) { - rtn = copywin(self->win, temp->win, sminrow, smincol, - dminrow, dmincol, dmaxrow, dmaxcol, FALSE); - return PyCursesCheckERR(rtn, "copywin"); - } - else { - rtn = overwrite(self->win, temp->win); - return PyCursesCheckERR(rtn, "overwrite"); - } -} - -static PyObject * -PyCursesWindow_PutWin(PyCursesWindowObject *self, PyObject *stream) -{ - /* We have to simulate this by writing to a temporary FILE*, - then reading back, then writing to the argument stream. */ - char fn[100]; - int fd = -1; - FILE *fp = NULL; - PyObject *res = NULL; - - strcpy(fn, "/tmp/py.curses.putwin.XXXXXX"); - fd = mkstemp(fn); - if (fd < 0) - return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); - if (_Py_set_inheritable(fd, 0, NULL) < 0) - goto exit; - fp = fdopen(fd, "wb+"); - if (fp == NULL) { - PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); - goto exit; - } - res = PyCursesCheckERR(putwin(self->win, fp), "putwin"); - if (res == NULL) - goto exit; - fseek(fp, 0, 0); - while (1) { - char buf[BUFSIZ]; - Py_ssize_t n = fread(buf, 1, BUFSIZ, fp); - _Py_IDENTIFIER(write); - - if (n <= 0) - break; - Py_DECREF(res); - res = _PyObject_CallMethodId(stream, &PyId_write, "y#", buf, n); - if (res == NULL) - break; - } - -exit: - if (fp != NULL) - fclose(fp); - else if (fd != -1) - close(fd); - remove(fn); - return res; -} - -static PyObject * -PyCursesWindow_RedrawLine(PyCursesWindowObject *self, PyObject *args) -{ - int beg, num; - if (!PyArg_ParseTuple(args, "ii;beg,num", &beg, &num)) - return NULL; - return PyCursesCheckERR(wredrawln(self->win,beg,num), "redrawln"); -} - -static PyObject * -PyCursesWindow_Refresh(PyCursesWindowObject *self, PyObject *args) -{ - int pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol; - int rtn; - -#ifndef py_is_pad - if (0) -#else - if (py_is_pad(self->win)) -#endif - { - switch(PyTuple_Size(args)) { - case 6: - if (!PyArg_ParseTuple(args, - "iiiiii;" \ - "pminrow,pmincol,sminrow,smincol,smaxrow,smaxcol", - &pminrow, &pmincol, &sminrow, - &smincol, &smaxrow, &smaxcol)) - return NULL; - - Py_BEGIN_ALLOW_THREADS - rtn = prefresh(self->win, - pminrow, pmincol, sminrow, - smincol, smaxrow, smaxcol); - Py_END_ALLOW_THREADS - return PyCursesCheckERR(rtn, "prefresh"); - default: - PyErr_SetString(PyCursesError, - "refresh() for a pad requires 6 arguments"); - return NULL; - } - } else { - if (!PyArg_ParseTuple(args, ":refresh")) - return NULL; - Py_BEGIN_ALLOW_THREADS - rtn = wrefresh(self->win); - Py_END_ALLOW_THREADS - return PyCursesCheckERR(rtn, "prefresh"); - } -} - -static PyObject * -PyCursesWindow_SetScrollRegion(PyCursesWindowObject *self, PyObject *args) -{ - int x, y; - if (!PyArg_ParseTuple(args,"ii;top, bottom",&y,&x)) - return NULL; - return PyCursesCheckERR(wsetscrreg(self->win,y,x), "wsetscrreg"); -} - -static PyObject * -PyCursesWindow_SubWin(PyCursesWindowObject *self, PyObject *args) -{ - WINDOW *win; - int nlines, ncols, begin_y, begin_x; - - nlines = 0; - ncols = 0; - switch (PyTuple_Size(args)) { - case 2: - if (!PyArg_ParseTuple(args,"ii;begin_y,begin_x",&begin_y,&begin_x)) - return NULL; - break; - case 4: - if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x", - &nlines,&ncols,&begin_y,&begin_x)) - return NULL; - break; - default: - PyErr_SetString(PyExc_TypeError, "subwin requires 2 or 4 arguments"); - return NULL; - } - - /* printf("Subwin: %i %i %i %i \n", nlines, ncols, begin_y, begin_x); */ -#ifdef py_is_pad - if (py_is_pad(self->win)) { - win = subpad(self->win, nlines, ncols, begin_y, begin_x); - } - else -#endif - win = subwin(self->win, nlines, ncols, begin_y, begin_x); - - if (win == NULL) { - PyErr_SetString(PyCursesError, catchall_NULL); - return NULL; - } - - return (PyObject *)PyCursesWindow_New(win, self->encoding); -} - -static PyObject * -PyCursesWindow_Scroll(PyCursesWindowObject *self, PyObject *args) -{ - int nlines; - switch(PyTuple_Size(args)) { - case 0: - return PyCursesCheckERR(scroll(self->win), "scroll"); - case 1: - if (!PyArg_ParseTuple(args, "i;nlines", &nlines)) - return NULL; - return PyCursesCheckERR(wscrl(self->win, nlines), "scroll"); - default: - PyErr_SetString(PyExc_TypeError, "scroll requires 0 or 1 arguments"); - return NULL; - } -} - -static PyObject * -PyCursesWindow_TouchLine(PyCursesWindowObject *self, PyObject *args) -{ - int st, cnt, val; - switch (PyTuple_Size(args)) { - case 2: - if (!PyArg_ParseTuple(args,"ii;start,count",&st,&cnt)) - return NULL; - return PyCursesCheckERR(touchline(self->win,st,cnt), "touchline"); - case 3: - if (!PyArg_ParseTuple(args, "iii;start,count,val", &st, &cnt, &val)) - return NULL; - return PyCursesCheckERR(wtouchln(self->win, st, cnt, val), "touchline"); - default: - PyErr_SetString(PyExc_TypeError, "touchline requires 2 or 3 arguments"); - return NULL; - } -} - -static PyObject * -PyCursesWindow_Vline(PyCursesWindowObject *self, PyObject *args) -{ - PyObject *temp; - chtype ch; - int n, x, y, code = OK; - attr_t attr = A_NORMAL; - long lattr; - - switch (PyTuple_Size(args)) { - case 2: - if (!PyArg_ParseTuple(args, "Oi;ch or int,n", &temp, &n)) - return NULL; - break; - case 3: - if (!PyArg_ParseTuple(args, "Oil;ch or int,n,attr", &temp, &n, &lattr)) - return NULL; - attr = lattr; - break; - case 4: - if (!PyArg_ParseTuple(args, "iiOi;y,x,ch or int,n", &y, &x, &temp, &n)) - return NULL; - code = wmove(self->win, y, x); - break; - case 5: - if (!PyArg_ParseTuple(args, "iiOil; y,x,ch or int,n,attr", - &y, &x, &temp, &n, &lattr)) - return NULL; - attr = lattr; - code = wmove(self->win, y, x); - break; - default: - PyErr_SetString(PyExc_TypeError, "vline requires 2 to 5 arguments"); - return NULL; - } - - if (code != ERR) { - if (!PyCurses_ConvertToChtype(self, temp, &ch)) - return NULL; - return PyCursesCheckERR(wvline(self->win, ch | attr, n), "vline"); - } else - return PyCursesCheckERR(code, "wmove"); -} - -static PyObject * -PyCursesWindow_get_encoding(PyCursesWindowObject *self, void *closure) -{ - return PyUnicode_FromString(self->encoding); -} - -static int -PyCursesWindow_set_encoding(PyCursesWindowObject *self, PyObject *value, void *Py_UNUSED(ignored)) -{ - PyObject *ascii; - char *encoding; - - /* It is illegal to del win.encoding */ - if (value == NULL) { - PyErr_SetString(PyExc_TypeError, - "encoding may not be deleted"); - return -1; - } - - if (!PyUnicode_Check(value)) { - PyErr_SetString(PyExc_TypeError, - "setting encoding to a non-string"); - return -1; - } - ascii = PyUnicode_AsASCIIString(value); - if (ascii == NULL) - return -1; - encoding = _PyMem_Strdup(PyBytes_AS_STRING(ascii)); - Py_DECREF(ascii); - if (encoding == NULL) { - PyErr_NoMemory(); - return -1; - } - PyMem_Free(self->encoding); - self->encoding = encoding; - return 0; -} - - -static PyMethodDef PyCursesWindow_Methods[] = { - CURSES_WINDOW_ADDCH_METHODDEF - {"addnstr", (PyCFunction)PyCursesWindow_AddNStr, METH_VARARGS}, - {"addstr", (PyCFunction)PyCursesWindow_AddStr, METH_VARARGS}, - {"attroff", (PyCFunction)PyCursesWindow_AttrOff, METH_VARARGS}, - {"attron", (PyCFunction)PyCursesWindow_AttrOn, METH_VARARGS}, - {"attrset", (PyCFunction)PyCursesWindow_AttrSet, METH_VARARGS}, - {"bkgd", (PyCFunction)PyCursesWindow_Bkgd, METH_VARARGS}, -#ifdef HAVE_CURSES_WCHGAT - {"chgat", (PyCFunction)PyCursesWindow_ChgAt, METH_VARARGS}, -#endif - {"bkgdset", (PyCFunction)PyCursesWindow_BkgdSet, METH_VARARGS}, - {"border", (PyCFunction)PyCursesWindow_Border, METH_VARARGS}, - {"box", (PyCFunction)PyCursesWindow_Box, METH_VARARGS}, - {"clear", (PyCFunction)PyCursesWindow_wclear, METH_NOARGS}, - {"clearok", (PyCFunction)PyCursesWindow_clearok, METH_VARARGS}, - {"clrtobot", (PyCFunction)PyCursesWindow_wclrtobot, METH_NOARGS}, - {"clrtoeol", (PyCFunction)PyCursesWindow_wclrtoeol, METH_NOARGS}, - {"cursyncup", (PyCFunction)PyCursesWindow_wcursyncup, METH_NOARGS}, - {"delch", (PyCFunction)PyCursesWindow_DelCh, METH_VARARGS}, - {"deleteln", (PyCFunction)PyCursesWindow_wdeleteln, METH_NOARGS}, - {"derwin", (PyCFunction)PyCursesWindow_DerWin, METH_VARARGS}, - {"echochar", (PyCFunction)PyCursesWindow_EchoChar, METH_VARARGS}, -#ifdef NCURSES_MOUSE_VERSION - {"enclose", (PyCFunction)PyCursesWindow_Enclose, METH_VARARGS}, -#endif - {"erase", (PyCFunction)PyCursesWindow_werase, METH_NOARGS}, - {"getbegyx", (PyCFunction)PyCursesWindow_getbegyx, METH_NOARGS}, - {"getbkgd", (PyCFunction)PyCursesWindow_GetBkgd, METH_NOARGS}, - {"getch", (PyCFunction)PyCursesWindow_GetCh, METH_VARARGS}, - {"getkey", (PyCFunction)PyCursesWindow_GetKey, METH_VARARGS}, -#ifdef HAVE_NCURSESW - {"get_wch", (PyCFunction)PyCursesWindow_Get_WCh, METH_VARARGS}, -#endif - {"getmaxyx", (PyCFunction)PyCursesWindow_getmaxyx, METH_NOARGS}, - {"getparyx", (PyCFunction)PyCursesWindow_getparyx, METH_NOARGS}, - {"getstr", (PyCFunction)PyCursesWindow_GetStr, METH_VARARGS}, - {"getyx", (PyCFunction)PyCursesWindow_getyx, METH_NOARGS}, - {"hline", (PyCFunction)PyCursesWindow_Hline, METH_VARARGS}, - {"idcok", (PyCFunction)PyCursesWindow_idcok, METH_VARARGS}, - {"idlok", (PyCFunction)PyCursesWindow_idlok, METH_VARARGS}, -#ifdef HAVE_CURSES_IMMEDOK - {"immedok", (PyCFunction)PyCursesWindow_immedok, METH_VARARGS}, -#endif - {"inch", (PyCFunction)PyCursesWindow_InCh, METH_VARARGS}, - {"insch", (PyCFunction)PyCursesWindow_InsCh, METH_VARARGS}, - {"insdelln", (PyCFunction)PyCursesWindow_winsdelln, METH_VARARGS}, - {"insertln", (PyCFunction)PyCursesWindow_winsertln, METH_NOARGS}, - {"insnstr", (PyCFunction)PyCursesWindow_InsNStr, METH_VARARGS}, - {"insstr", (PyCFunction)PyCursesWindow_InsStr, METH_VARARGS}, - {"instr", (PyCFunction)PyCursesWindow_InStr, METH_VARARGS}, - {"is_linetouched", (PyCFunction)PyCursesWindow_Is_LineTouched, METH_VARARGS}, - {"is_wintouched", (PyCFunction)PyCursesWindow_is_wintouched, METH_NOARGS}, - {"keypad", (PyCFunction)PyCursesWindow_keypad, METH_VARARGS}, - {"leaveok", (PyCFunction)PyCursesWindow_leaveok, METH_VARARGS}, - {"move", (PyCFunction)PyCursesWindow_wmove, METH_VARARGS}, - {"mvderwin", (PyCFunction)PyCursesWindow_mvderwin, METH_VARARGS}, - {"mvwin", (PyCFunction)PyCursesWindow_mvwin, METH_VARARGS}, - {"nodelay", (PyCFunction)PyCursesWindow_nodelay, METH_VARARGS}, - {"notimeout", (PyCFunction)PyCursesWindow_notimeout, METH_VARARGS}, - {"noutrefresh", (PyCFunction)PyCursesWindow_NoOutRefresh, METH_VARARGS}, - {"overlay", (PyCFunction)PyCursesWindow_Overlay, METH_VARARGS}, - {"overwrite", (PyCFunction)PyCursesWindow_Overwrite, - METH_VARARGS}, - {"putwin", (PyCFunction)PyCursesWindow_PutWin, METH_O}, - {"redrawln", (PyCFunction)PyCursesWindow_RedrawLine, METH_VARARGS}, - {"redrawwin", (PyCFunction)PyCursesWindow_redrawwin, METH_NOARGS}, - {"refresh", (PyCFunction)PyCursesWindow_Refresh, METH_VARARGS}, -#ifndef STRICT_SYSV_CURSES - {"resize", (PyCFunction)PyCursesWindow_wresize, METH_VARARGS}, -#endif - {"scroll", (PyCFunction)PyCursesWindow_Scroll, METH_VARARGS}, - {"scrollok", (PyCFunction)PyCursesWindow_scrollok, METH_VARARGS}, - {"setscrreg", (PyCFunction)PyCursesWindow_SetScrollRegion, METH_VARARGS}, - {"standend", (PyCFunction)PyCursesWindow_wstandend, METH_NOARGS}, - {"standout", (PyCFunction)PyCursesWindow_wstandout, METH_NOARGS}, - {"subpad", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS}, - {"subwin", (PyCFunction)PyCursesWindow_SubWin, METH_VARARGS}, - {"syncdown", (PyCFunction)PyCursesWindow_wsyncdown, METH_NOARGS}, -#ifdef HAVE_CURSES_SYNCOK - {"syncok", (PyCFunction)PyCursesWindow_syncok, METH_VARARGS}, -#endif - {"syncup", (PyCFunction)PyCursesWindow_wsyncup, METH_NOARGS}, - {"timeout", (PyCFunction)PyCursesWindow_wtimeout, METH_VARARGS}, - {"touchline", (PyCFunction)PyCursesWindow_TouchLine, METH_VARARGS}, - {"touchwin", (PyCFunction)PyCursesWindow_touchwin, METH_NOARGS}, - {"untouchwin", (PyCFunction)PyCursesWindow_untouchwin, METH_NOARGS}, - {"vline", (PyCFunction)PyCursesWindow_Vline, METH_VARARGS}, - {NULL, NULL} /* sentinel */ -}; - -static PyGetSetDef PyCursesWindow_getsets[] = { - {"encoding", - (getter)PyCursesWindow_get_encoding, - (setter)PyCursesWindow_set_encoding, - "the typecode character used to create the array"}, - {NULL, NULL, NULL, NULL } /* sentinel */ -}; - -/* -------------------------------------------------------*/ - -PyTypeObject PyCursesWindow_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_curses.window", /*tp_name*/ - sizeof(PyCursesWindowObject), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - /* methods */ - (destructor)PyCursesWindow_Dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - (getattrfunc)0, /*tp_getattr*/ - (setattrfunc)0, /*tp_setattr*/ - 0, /*tp_reserved*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT, /*tp_flags*/ - 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - PyCursesWindow_Methods, /*tp_methods*/ - 0, /* tp_members */ - PyCursesWindow_getsets, /* tp_getset */ -}; - -/********************************************************************* - Global Functions -**********************************************************************/ - -NoArgNoReturnFunction(beep) -NoArgNoReturnFunction(def_prog_mode) -NoArgNoReturnFunction(def_shell_mode) -NoArgNoReturnFunction(doupdate) -NoArgNoReturnFunction(endwin) -NoArgNoReturnFunction(flash) -NoArgNoReturnFunction(nocbreak) -NoArgNoReturnFunction(noecho) -NoArgNoReturnFunction(nonl) -NoArgNoReturnFunction(noraw) -NoArgNoReturnFunction(reset_prog_mode) -NoArgNoReturnFunction(reset_shell_mode) -NoArgNoReturnFunction(resetty) -NoArgNoReturnFunction(savetty) - -NoArgOrFlagNoReturnFunction(cbreak) -NoArgOrFlagNoReturnFunction(echo) -NoArgOrFlagNoReturnFunction(nl) -NoArgOrFlagNoReturnFunction(raw) - -NoArgReturnIntFunction(baudrate) -NoArgReturnIntFunction(termattrs) - -NoArgReturnStringFunction(termname) -NoArgReturnStringFunction(longname) - -NoArgTrueFalseFunction(can_change_color) -NoArgTrueFalseFunction(has_colors) -NoArgTrueFalseFunction(has_ic) -NoArgTrueFalseFunction(has_il) -NoArgTrueFalseFunction(isendwin) -NoArgNoReturnVoidFunction(flushinp) -NoArgNoReturnVoidFunction(noqiflush) - -#ifdef HAVE_CURSES_FILTER -static PyObject * -PyCurses_filter(PyObject *self) -{ - /* not checking for PyCursesInitialised here since filter() must - be called before initscr() */ - filter(); - Py_INCREF(Py_None); - return Py_None; -} -#endif - -static PyObject * -PyCurses_Color_Content(PyObject *self, PyObject *args) -{ - short color,r,g,b; - - PyCursesInitialised; - PyCursesInitialisedColor; - - if (!PyArg_ParseTuple(args, "h:color_content", &color)) return NULL; - - if (color_content(color, &r, &g, &b) != ERR) - return Py_BuildValue("(iii)", r, g, b); - else { - PyErr_SetString(PyCursesError, - "Argument 1 was out of range. Check value of COLORS."); - return NULL; - } -} - -static PyObject * -PyCurses_color_pair(PyObject *self, PyObject *args) -{ - int n; - - PyCursesInitialised; - PyCursesInitialisedColor; - - if (!PyArg_ParseTuple(args, "i:color_pair", &n)) return NULL; - return PyLong_FromLong((long) (n << 8)); -} - -static PyObject * -PyCurses_Curs_Set(PyObject *self, PyObject *args) -{ - int vis,erg; - - PyCursesInitialised; - - if (!PyArg_ParseTuple(args, "i:curs_set", &vis)) return NULL; - - erg = curs_set(vis); - if (erg == ERR) return PyCursesCheckERR(erg, "curs_set"); - - return PyLong_FromLong((long) erg); -} - -static PyObject * -PyCurses_Delay_Output(PyObject *self, PyObject *args) -{ - int ms; - - PyCursesInitialised; - - if (!PyArg_ParseTuple(args, "i:delay_output", &ms)) return NULL; - - return PyCursesCheckERR(delay_output(ms), "delay_output"); -} - -static PyObject * -PyCurses_EraseChar(PyObject *self) -{ - char ch; - - PyCursesInitialised; - - ch = erasechar(); - - return PyBytes_FromStringAndSize(&ch, 1); -} - -#ifdef getsyx -static PyObject * -PyCurses_getsyx(PyObject *self) -{ - int x = 0; - int y = 0; - - PyCursesInitialised; - - getsyx(y, x); - - return Py_BuildValue("(ii)", y, x); -} -#endif - -#ifdef NCURSES_MOUSE_VERSION -static PyObject * -PyCurses_GetMouse(PyObject *self) -{ - int rtn; - MEVENT event; - - PyCursesInitialised; - - rtn = getmouse( &event ); - if (rtn == ERR) { - PyErr_SetString(PyCursesError, "getmouse() returned ERR"); - return NULL; - } - return Py_BuildValue("(hiiik)", - (short)event.id, - (int)event.x, (int)event.y, (int)event.z, - (unsigned long) event.bstate); -} - -static PyObject * -PyCurses_UngetMouse(PyObject *self, PyObject *args) -{ - MEVENT event; - short id; - int x, y, z; - unsigned long bstate; - - PyCursesInitialised; - if (!PyArg_ParseTuple(args, "hiiik", - &id, &x, &y, &z, &bstate)) - return NULL; - - event.id = id; - event.x = x; - event.y = y; - event.z = z; - event.bstate = bstate; - return PyCursesCheckERR(ungetmouse(&event), "ungetmouse"); -} -#endif - -static PyObject * -PyCurses_GetWin(PyCursesWindowObject *self, PyObject *stream) -{ - char fn[100]; - int fd = -1; - FILE *fp = NULL; - PyObject *data; - size_t datalen; - WINDOW *win; - _Py_IDENTIFIER(read); - PyObject *res = NULL; - - PyCursesInitialised; - - strcpy(fn, "/tmp/py.curses.getwin.XXXXXX"); - fd = mkstemp(fn); - if (fd < 0) - return PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); - if (_Py_set_inheritable(fd, 0, NULL) < 0) - goto error; - fp = fdopen(fd, "wb+"); - if (fp == NULL) { - PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); - goto error; - } - - data = _PyObject_CallMethodId(stream, &PyId_read, NULL); - if (data == NULL) - goto error; - if (!PyBytes_Check(data)) { - PyErr_Format(PyExc_TypeError, - "f.read() returned %.100s instead of bytes", - data->ob_type->tp_name); - Py_DECREF(data); - goto error; - } - datalen = PyBytes_GET_SIZE(data); - if (fwrite(PyBytes_AS_STRING(data), 1, datalen, fp) != datalen) { - Py_DECREF(data); - PyErr_SetFromErrnoWithFilename(PyExc_IOError, fn); - goto error; - } - Py_DECREF(data); - - fseek(fp, 0, 0); - win = getwin(fp); - if (win == NULL) { - PyErr_SetString(PyCursesError, catchall_NULL); - goto error; - } - res = PyCursesWindow_New(win, NULL); - -error: - if (fp != NULL) - fclose(fp); - else if (fd != -1) - close(fd); - remove(fn); - return res; -} - -static PyObject * -PyCurses_HalfDelay(PyObject *self, PyObject *args) -{ - unsigned char tenths; - - PyCursesInitialised; - - if (!PyArg_ParseTuple(args, "b:halfdelay", &tenths)) return NULL; - - return PyCursesCheckERR(halfdelay(tenths), "halfdelay"); -} - -#ifdef HAVE_CURSES_HAS_KEY -static PyObject * -PyCurses_has_key(PyObject *self, PyObject *args) -{ - int ch; - - PyCursesInitialised; - - if (!PyArg_ParseTuple(args,"i",&ch)) return NULL; - - if (has_key(ch) == FALSE) { - Py_INCREF(Py_False); - return Py_False; - } - Py_INCREF(Py_True); - return Py_True; -} -#endif - -static PyObject * -PyCurses_Init_Color(PyObject *self, PyObject *args) -{ - short color, r, g, b; - - PyCursesInitialised; - PyCursesInitialisedColor; - - switch(PyTuple_Size(args)) { - case 4: - if (!PyArg_ParseTuple(args, "hhhh;color,r,g,b", &color, &r, &g, &b)) return NULL; - break; - default: - PyErr_SetString(PyExc_TypeError, "init_color requires 4 arguments"); - return NULL; - } - - return PyCursesCheckERR(init_color(color, r, g, b), "init_color"); -} - -static PyObject * -PyCurses_Init_Pair(PyObject *self, PyObject *args) -{ - short pair, f, b; - - PyCursesInitialised; - PyCursesInitialisedColor; - - if (PyTuple_Size(args) != 3) { - PyErr_SetString(PyExc_TypeError, "init_pair requires 3 arguments"); - return NULL; - } - - if (!PyArg_ParseTuple(args, "hhh;pair, f, b", &pair, &f, &b)) return NULL; - - return PyCursesCheckERR(init_pair(pair, f, b), "init_pair"); -} - -static PyObject *ModDict; - -static PyObject * -PyCurses_InitScr(PyObject *self) -{ - WINDOW *win; - PyCursesWindowObject *winobj; - - if (initialised == TRUE) { - wrefresh(stdscr); - return (PyObject *)PyCursesWindow_New(stdscr, NULL); - } - - win = initscr(); - - if (win == NULL) { - PyErr_SetString(PyCursesError, catchall_NULL); - return NULL; - } - - initialised = initialised_setupterm = TRUE; - -/* This was moved from initcurses() because it core dumped on SGI, - where they're not defined until you've called initscr() */ -#define SetDictInt(string,ch) \ - do { \ - PyObject *o = PyLong_FromLong((long) (ch)); \ - if (o && PyDict_SetItemString(ModDict, string, o) == 0) { \ - Py_DECREF(o); \ - } \ - } while (0) - - /* Here are some graphic symbols you can use */ - SetDictInt("ACS_ULCORNER", (ACS_ULCORNER)); - SetDictInt("ACS_LLCORNER", (ACS_LLCORNER)); - SetDictInt("ACS_URCORNER", (ACS_URCORNER)); - SetDictInt("ACS_LRCORNER", (ACS_LRCORNER)); - SetDictInt("ACS_LTEE", (ACS_LTEE)); - SetDictInt("ACS_RTEE", (ACS_RTEE)); - SetDictInt("ACS_BTEE", (ACS_BTEE)); - SetDictInt("ACS_TTEE", (ACS_TTEE)); - SetDictInt("ACS_HLINE", (ACS_HLINE)); - SetDictInt("ACS_VLINE", (ACS_VLINE)); - SetDictInt("ACS_PLUS", (ACS_PLUS)); -#if !defined(__hpux) || defined(HAVE_NCURSES_H) - /* On HP/UX 11, these are of type cchar_t, which is not an - integral type. If this is a problem on more platforms, a - configure test should be added to determine whether ACS_S1 - is of integral type. */ - SetDictInt("ACS_S1", (ACS_S1)); - SetDictInt("ACS_S9", (ACS_S9)); - SetDictInt("ACS_DIAMOND", (ACS_DIAMOND)); - SetDictInt("ACS_CKBOARD", (ACS_CKBOARD)); - SetDictInt("ACS_DEGREE", (ACS_DEGREE)); - SetDictInt("ACS_PLMINUS", (ACS_PLMINUS)); - SetDictInt("ACS_BULLET", (ACS_BULLET)); - SetDictInt("ACS_LARROW", (ACS_LARROW)); - SetDictInt("ACS_RARROW", (ACS_RARROW)); - SetDictInt("ACS_DARROW", (ACS_DARROW)); - SetDictInt("ACS_UARROW", (ACS_UARROW)); - SetDictInt("ACS_BOARD", (ACS_BOARD)); - SetDictInt("ACS_LANTERN", (ACS_LANTERN)); - SetDictInt("ACS_BLOCK", (ACS_BLOCK)); -#endif - SetDictInt("ACS_BSSB", (ACS_ULCORNER)); - SetDictInt("ACS_SSBB", (ACS_LLCORNER)); - SetDictInt("ACS_BBSS", (ACS_URCORNER)); - SetDictInt("ACS_SBBS", (ACS_LRCORNER)); - SetDictInt("ACS_SBSS", (ACS_RTEE)); - SetDictInt("ACS_SSSB", (ACS_LTEE)); - SetDictInt("ACS_SSBS", (ACS_BTEE)); - SetDictInt("ACS_BSSS", (ACS_TTEE)); - SetDictInt("ACS_BSBS", (ACS_HLINE)); - SetDictInt("ACS_SBSB", (ACS_VLINE)); - SetDictInt("ACS_SSSS", (ACS_PLUS)); - - /* The following are never available with strict SYSV curses */ -#ifdef ACS_S3 - SetDictInt("ACS_S3", (ACS_S3)); -#endif -#ifdef ACS_S7 - SetDictInt("ACS_S7", (ACS_S7)); -#endif -#ifdef ACS_LEQUAL - SetDictInt("ACS_LEQUAL", (ACS_LEQUAL)); -#endif -#ifdef ACS_GEQUAL - SetDictInt("ACS_GEQUAL", (ACS_GEQUAL)); -#endif -#ifdef ACS_PI - SetDictInt("ACS_PI", (ACS_PI)); -#endif -#ifdef ACS_NEQUAL - SetDictInt("ACS_NEQUAL", (ACS_NEQUAL)); -#endif -#ifdef ACS_STERLING - SetDictInt("ACS_STERLING", (ACS_STERLING)); -#endif - - SetDictInt("LINES", LINES); - SetDictInt("COLS", COLS); - - winobj = (PyCursesWindowObject *)PyCursesWindow_New(win, NULL); - screen_encoding = winobj->encoding; - return (PyObject *)winobj; -} - -static PyObject * -PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds) -{ - int fd = -1; - int err; - char* termstr = NULL; - - static char *kwlist[] = {"term", "fd", NULL}; - - if (!PyArg_ParseTupleAndKeywords( - args, keywds, "|zi:setupterm", kwlist, &termstr, &fd)) { - return NULL; - } - - if (fd == -1) { - PyObject* sys_stdout; - - sys_stdout = PySys_GetObject("stdout"); - - if (sys_stdout == NULL || sys_stdout == Py_None) { - PyErr_SetString( - PyCursesError, - "lost sys.stdout"); - return NULL; - } - - fd = PyObject_AsFileDescriptor(sys_stdout); - - if (fd == -1) { - return NULL; - } - } - - if (!initialised_setupterm && setupterm(termstr,fd,&err) == ERR) { - char* s = "setupterm: unknown error"; - - if (err == 0) { - s = "setupterm: could not find terminal"; - } else if (err == -1) { - s = "setupterm: could not find terminfo database"; - } - - PyErr_SetString(PyCursesError,s); - return NULL; - } - - initialised_setupterm = TRUE; - - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject * -PyCurses_IntrFlush(PyObject *self, PyObject *args) -{ - int ch; - - PyCursesInitialised; - - switch(PyTuple_Size(args)) { - case 1: - if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL; - break; - default: - PyErr_SetString(PyExc_TypeError, "intrflush requires 1 argument"); - return NULL; - } - - return PyCursesCheckERR(intrflush(NULL,ch), "intrflush"); -} - -#ifdef HAVE_CURSES_IS_TERM_RESIZED -static PyObject * -PyCurses_Is_Term_Resized(PyObject *self, PyObject *args) -{ - int lines; - int columns; - int result; - - PyCursesInitialised; - - if (!PyArg_ParseTuple(args,"ii:is_term_resized", &lines, &columns)) - return NULL; - result = is_term_resized(lines, columns); - if (result == TRUE) { - Py_INCREF(Py_True); - return Py_True; - } else { - Py_INCREF(Py_False); - return Py_False; - } -} -#endif /* HAVE_CURSES_IS_TERM_RESIZED */ - -static PyObject * -PyCurses_KeyName(PyObject *self, PyObject *args) -{ - const char *knp; - int ch; - - PyCursesInitialised; - - if (!PyArg_ParseTuple(args,"i",&ch)) return NULL; - - if (ch < 0) { - PyErr_SetString(PyExc_ValueError, "invalid key number"); - return NULL; - } - knp = keyname(ch); - - return PyBytes_FromString((knp == NULL) ? "" : knp); -} - -static PyObject * -PyCurses_KillChar(PyObject *self) -{ - char ch; - - ch = killchar(); - - return PyBytes_FromStringAndSize(&ch, 1); -} - -static PyObject * -PyCurses_Meta(PyObject *self, PyObject *args) -{ - int ch; - - PyCursesInitialised; - - switch(PyTuple_Size(args)) { - case 1: - if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&ch)) return NULL; - break; - default: - PyErr_SetString(PyExc_TypeError, "meta requires 1 argument"); - return NULL; - } - - return PyCursesCheckERR(meta(stdscr, ch), "meta"); -} - -#ifdef NCURSES_MOUSE_VERSION -static PyObject * -PyCurses_MouseInterval(PyObject *self, PyObject *args) -{ - int interval; - PyCursesInitialised; - - if (!PyArg_ParseTuple(args,"i;interval",&interval)) - return NULL; - return PyCursesCheckERR(mouseinterval(interval), "mouseinterval"); -} - -static PyObject * -PyCurses_MouseMask(PyObject *self, PyObject *args) -{ - unsigned long newmask; - mmask_t oldmask, availmask; - - PyCursesInitialised; - if (!PyArg_ParseTuple(args,"k;mousemask",&newmask)) - return NULL; - availmask = mousemask((mmask_t)newmask, &oldmask); - return Py_BuildValue("(kk)", - (unsigned long)availmask, (unsigned long)oldmask); -} -#endif - -static PyObject * -PyCurses_Napms(PyObject *self, PyObject *args) -{ - int ms; - - PyCursesInitialised; - if (!PyArg_ParseTuple(args, "i;ms", &ms)) return NULL; - - return Py_BuildValue("i", napms(ms)); -} - - -static PyObject * -PyCurses_NewPad(PyObject *self, PyObject *args) -{ - WINDOW *win; - int nlines, ncols; - - PyCursesInitialised; - - if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols)) return NULL; - - win = newpad(nlines, ncols); - - if (win == NULL) { - PyErr_SetString(PyCursesError, catchall_NULL); - return NULL; - } - - return (PyObject *)PyCursesWindow_New(win, NULL); -} - -static PyObject * -PyCurses_NewWindow(PyObject *self, PyObject *args) -{ - WINDOW *win; - int nlines, ncols, begin_y=0, begin_x=0; - - PyCursesInitialised; - - switch (PyTuple_Size(args)) { - case 2: - if (!PyArg_ParseTuple(args,"ii;nlines,ncols",&nlines,&ncols)) - return NULL; - break; - case 4: - if (!PyArg_ParseTuple(args, "iiii;nlines,ncols,begin_y,begin_x", - &nlines,&ncols,&begin_y,&begin_x)) - return NULL; - break; - default: - PyErr_SetString(PyExc_TypeError, "newwin requires 2 or 4 arguments"); - return NULL; - } - - win = newwin(nlines,ncols,begin_y,begin_x); - if (win == NULL) { - PyErr_SetString(PyCursesError, catchall_NULL); - return NULL; - } - - return (PyObject *)PyCursesWindow_New(win, NULL); -} - -static PyObject * -PyCurses_Pair_Content(PyObject *self, PyObject *args) -{ - short pair,f,b; - - PyCursesInitialised; - PyCursesInitialisedColor; - - switch(PyTuple_Size(args)) { - case 1: - if (!PyArg_ParseTuple(args, "h;pair", &pair)) return NULL; - break; - default: - PyErr_SetString(PyExc_TypeError, "pair_content requires 1 argument"); - return NULL; - } - - if (pair_content(pair, &f, &b)==ERR) { - PyErr_SetString(PyCursesError, - "Argument 1 was out of range. (1..COLOR_PAIRS-1)"); - return NULL; - } - - return Py_BuildValue("(ii)", f, b); -} - -static PyObject * -PyCurses_pair_number(PyObject *self, PyObject *args) -{ - int n; - - PyCursesInitialised; - PyCursesInitialisedColor; - - switch(PyTuple_Size(args)) { - case 1: - if (!PyArg_ParseTuple(args, "i;pairvalue", &n)) return NULL; - break; - default: - PyErr_SetString(PyExc_TypeError, - "pair_number requires 1 argument"); - return NULL; - } - - return PyLong_FromLong((long) ((n & A_COLOR) >> 8)); -} - -static PyObject * -PyCurses_Putp(PyObject *self, PyObject *args) -{ - char *str; - - if (!PyArg_ParseTuple(args,"y;str", &str)) - return NULL; - return PyCursesCheckERR(putp(str), "putp"); -} - -static PyObject * -PyCurses_QiFlush(PyObject *self, PyObject *args) -{ - int flag = 0; - - PyCursesInitialised; - - switch(PyTuple_Size(args)) { - case 0: - qiflush(); - Py_INCREF(Py_None); - return Py_None; - case 1: - if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; - if (flag) qiflush(); - else noqiflush(); - Py_INCREF(Py_None); - return Py_None; - default: - PyErr_SetString(PyExc_TypeError, "qiflush requires 0 or 1 arguments"); - return NULL; - } -} - -/* Internal helper used for updating curses.LINES, curses.COLS, _curses.LINES - * and _curses.COLS */ -#if defined(HAVE_CURSES_RESIZETERM) || defined(HAVE_CURSES_RESIZE_TERM) -static int -update_lines_cols(void) -{ - PyObject *o; - PyObject *m = PyImport_ImportModuleNoBlock("curses"); - _Py_IDENTIFIER(LINES); - _Py_IDENTIFIER(COLS); - - if (!m) - return 0; - - o = PyLong_FromLong(LINES); - if (!o) { - Py_DECREF(m); - return 0; - } - if (_PyObject_SetAttrId(m, &PyId_LINES, o)) { - Py_DECREF(m); - Py_DECREF(o); - return 0; - } - /* PyId_LINES.object will be initialized here. */ - if (PyDict_SetItem(ModDict, PyId_LINES.object, o)) { - Py_DECREF(m); - Py_DECREF(o); - return 0; - } - Py_DECREF(o); - o = PyLong_FromLong(COLS); - if (!o) { - Py_DECREF(m); - return 0; - } - if (_PyObject_SetAttrId(m, &PyId_COLS, o)) { - Py_DECREF(m); - Py_DECREF(o); - return 0; - } - if (PyDict_SetItem(ModDict, PyId_COLS.object, o)) { - Py_DECREF(m); - Py_DECREF(o); - return 0; - } - Py_DECREF(o); - Py_DECREF(m); - return 1; -} - -static PyObject * -PyCurses_update_lines_cols(PyObject *self) -{ - return PyLong_FromLong((long) update_lines_cols()); -} - -#endif - -#ifdef HAVE_CURSES_RESIZETERM -static PyObject * -PyCurses_ResizeTerm(PyObject *self, PyObject *args) -{ - int lines; - int columns; - PyObject *result; - - PyCursesInitialised; - - if (!PyArg_ParseTuple(args,"ii:resizeterm", &lines, &columns)) - return NULL; - - result = PyCursesCheckERR(resizeterm(lines, columns), "resizeterm"); - if (!result) - return NULL; - if (!update_lines_cols()) - return NULL; - return result; -} - -#endif - -#ifdef HAVE_CURSES_RESIZE_TERM -static PyObject * -PyCurses_Resize_Term(PyObject *self, PyObject *args) -{ - int lines; - int columns; - - PyObject *result; - - PyCursesInitialised; - - if (!PyArg_ParseTuple(args,"ii:resize_term", &lines, &columns)) - return NULL; - - result = PyCursesCheckERR(resize_term(lines, columns), "resize_term"); - if (!result) - return NULL; - if (!update_lines_cols()) - return NULL; - return result; -} -#endif /* HAVE_CURSES_RESIZE_TERM */ - -#ifdef getsyx -static PyObject * -PyCurses_setsyx(PyObject *self, PyObject *args) -{ - int y,x; - - PyCursesInitialised; - - if (PyTuple_Size(args)!=2) { - PyErr_SetString(PyExc_TypeError, "setsyx requires 2 arguments"); - return NULL; - } - - if (!PyArg_ParseTuple(args, "ii;y, x", &y, &x)) return NULL; - - setsyx(y,x); - - Py_INCREF(Py_None); - return Py_None; -} -#endif - -static PyObject * -PyCurses_Start_Color(PyObject *self) -{ - int code; - PyObject *c, *cp; - - PyCursesInitialised; - - code = start_color(); - if (code != ERR) { - initialisedcolors = TRUE; - c = PyLong_FromLong((long) COLORS); - if (c == NULL) - return NULL; - PyDict_SetItemString(ModDict, "COLORS", c); - Py_DECREF(c); - cp = PyLong_FromLong((long) COLOR_PAIRS); - if (cp == NULL) - return NULL; - PyDict_SetItemString(ModDict, "COLOR_PAIRS", cp); - Py_DECREF(cp); - Py_INCREF(Py_None); - return Py_None; - } else { - PyErr_SetString(PyCursesError, "start_color() returned ERR"); - return NULL; - } -} - -static PyObject * -PyCurses_tigetflag(PyObject *self, PyObject *args) -{ - char *capname; - - PyCursesSetupTermCalled; - - if (!PyArg_ParseTuple(args, "s", &capname)) - return NULL; - - return PyLong_FromLong( (long) tigetflag( capname ) ); -} - -static PyObject * -PyCurses_tigetnum(PyObject *self, PyObject *args) -{ - char *capname; - - PyCursesSetupTermCalled; - - if (!PyArg_ParseTuple(args, "s", &capname)) - return NULL; - - return PyLong_FromLong( (long) tigetnum( capname ) ); -} - -static PyObject * -PyCurses_tigetstr(PyObject *self, PyObject *args) -{ - char *capname; - - PyCursesSetupTermCalled; - - if (!PyArg_ParseTuple(args, "s", &capname)) - return NULL; - - capname = tigetstr( capname ); - if (capname == 0 || capname == (char*) -1) { - Py_INCREF(Py_None); - return Py_None; - } - return PyBytes_FromString( capname ); -} - -static PyObject * -PyCurses_tparm(PyObject *self, PyObject *args) -{ - char* fmt; - char* result = NULL; - int i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0,i8=0,i9=0; - - PyCursesSetupTermCalled; - - if (!PyArg_ParseTuple(args, "y|iiiiiiiii:tparm", - &fmt, &i1, &i2, &i3, &i4, - &i5, &i6, &i7, &i8, &i9)) { - return NULL; - } - - result = tparm(fmt,i1,i2,i3,i4,i5,i6,i7,i8,i9); - if (!result) { - PyErr_SetString(PyCursesError, "tparm() returned NULL"); - return NULL; - } - - return PyBytes_FromString(result); -} - -#ifdef HAVE_CURSES_TYPEAHEAD -static PyObject * -PyCurses_TypeAhead(PyObject *self, PyObject *args) -{ - int fd; - - PyCursesInitialised; - - if (!PyArg_ParseTuple(args,"i;fd",&fd)) return NULL; - - return PyCursesCheckERR(typeahead( fd ), "typeahead"); -} -#endif - -static PyObject * -PyCurses_UnCtrl(PyObject *self, PyObject *args) -{ - PyObject *temp; - chtype ch; - - PyCursesInitialised; - - if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL; - - if (!PyCurses_ConvertToChtype(NULL, temp, &ch)) - return NULL; - - return PyBytes_FromString(unctrl(ch)); -} - -static PyObject * -PyCurses_UngetCh(PyObject *self, PyObject *args) -{ - PyObject *temp; - chtype ch; - - PyCursesInitialised; - - if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) - return NULL; - - if (!PyCurses_ConvertToChtype(NULL, temp, &ch)) - return NULL; - - return PyCursesCheckERR(ungetch(ch), "ungetch"); -} - -#ifdef HAVE_NCURSESW -/* Convert an object to a character (wchar_t): - - - int - - str of length 1 - - Return 1 on success, 0 on error. */ -static int -PyCurses_ConvertToWchar_t(PyObject *obj, - wchar_t *wch) -{ - if (PyUnicode_Check(obj)) { - wchar_t buffer[2]; - if (PyUnicode_AsWideChar(obj, buffer, 2) != 1) { - PyErr_Format(PyExc_TypeError, - "expect bytes or str of length 1, or int, " - "got a str of length %zi", - PyUnicode_GET_LENGTH(obj)); - return 0; - } - *wch = buffer[0]; - return 2; - } - else if (PyLong_CheckExact(obj)) { - long value; - int overflow; - value = PyLong_AsLongAndOverflow(obj, &overflow); - if (overflow) { - PyErr_SetString(PyExc_OverflowError, - "int doesn't fit in long"); - return 0; - } - *wch = (wchar_t)value; - if ((long)*wch != value) { - PyErr_Format(PyExc_OverflowError, - "character doesn't fit in wchar_t"); - return 0; - } - return 1; - } - else { - PyErr_Format(PyExc_TypeError, - "expect bytes or str of length 1, or int, got %s", - Py_TYPE(obj)->tp_name); - return 0; - } -} - -static PyObject * -PyCurses_Unget_Wch(PyObject *self, PyObject *args) -{ - PyObject *obj; - wchar_t wch; - - PyCursesInitialised; - - if (!PyArg_ParseTuple(args,"O", &obj)) - return NULL; - - if (!PyCurses_ConvertToWchar_t(obj, &wch)) - return NULL; - return PyCursesCheckERR(unget_wch(wch), "unget_wch"); -} -#endif - -#ifdef HAVE_CURSES_TYPEAHEAD -static PyObject * -PyCurses_Use_Env(PyObject *self, PyObject *args) -{ - int flag; - - switch(PyTuple_Size(args)) { - case 1: - if (!PyArg_ParseTuple(args,"i;True(1), False(0)",&flag)) - return NULL; - break; - default: - PyErr_SetString(PyExc_TypeError, "use_env requires 1 argument"); - return NULL; - } - use_env(flag); - Py_INCREF(Py_None); - return Py_None; -} -#endif - -#ifndef STRICT_SYSV_CURSES -static PyObject * -PyCurses_Use_Default_Colors(PyObject *self) -{ - int code; - - PyCursesInitialised; - PyCursesInitialisedColor; - - code = use_default_colors(); - if (code != ERR) { - Py_INCREF(Py_None); - return Py_None; - } else { - PyErr_SetString(PyCursesError, "use_default_colors() returned ERR"); - return NULL; - } -} -#endif /* STRICT_SYSV_CURSES */ - -/* List of functions defined in the module */ - -static PyMethodDef PyCurses_methods[] = { - {"baudrate", (PyCFunction)PyCurses_baudrate, METH_NOARGS}, - {"beep", (PyCFunction)PyCurses_beep, METH_NOARGS}, - {"can_change_color", (PyCFunction)PyCurses_can_change_color, METH_NOARGS}, - {"cbreak", (PyCFunction)PyCurses_cbreak, METH_VARARGS}, - {"color_content", (PyCFunction)PyCurses_Color_Content, METH_VARARGS}, - {"color_pair", (PyCFunction)PyCurses_color_pair, METH_VARARGS}, - {"curs_set", (PyCFunction)PyCurses_Curs_Set, METH_VARARGS}, - {"def_prog_mode", (PyCFunction)PyCurses_def_prog_mode, METH_NOARGS}, - {"def_shell_mode", (PyCFunction)PyCurses_def_shell_mode, METH_NOARGS}, - {"delay_output", (PyCFunction)PyCurses_Delay_Output, METH_VARARGS}, - {"doupdate", (PyCFunction)PyCurses_doupdate, METH_NOARGS}, - {"echo", (PyCFunction)PyCurses_echo, METH_VARARGS}, - {"endwin", (PyCFunction)PyCurses_endwin, METH_NOARGS}, - {"erasechar", (PyCFunction)PyCurses_EraseChar, METH_NOARGS}, -#ifdef HAVE_CURSES_FILTER - {"filter", (PyCFunction)PyCurses_filter, METH_NOARGS}, -#endif - {"flash", (PyCFunction)PyCurses_flash, METH_NOARGS}, - {"flushinp", (PyCFunction)PyCurses_flushinp, METH_NOARGS}, -#ifdef NCURSES_MOUSE_VERSION - {"getmouse", (PyCFunction)PyCurses_GetMouse, METH_NOARGS}, - {"ungetmouse", (PyCFunction)PyCurses_UngetMouse, METH_VARARGS}, -#endif -#ifdef getsyx - {"getsyx", (PyCFunction)PyCurses_getsyx, METH_NOARGS}, -#endif - {"getwin", (PyCFunction)PyCurses_GetWin, METH_O}, - {"has_colors", (PyCFunction)PyCurses_has_colors, METH_NOARGS}, - {"has_ic", (PyCFunction)PyCurses_has_ic, METH_NOARGS}, - {"has_il", (PyCFunction)PyCurses_has_il, METH_NOARGS}, -#ifdef HAVE_CURSES_HAS_KEY - {"has_key", (PyCFunction)PyCurses_has_key, METH_VARARGS}, -#endif - {"halfdelay", (PyCFunction)PyCurses_HalfDelay, METH_VARARGS}, - {"init_color", (PyCFunction)PyCurses_Init_Color, METH_VARARGS}, - {"init_pair", (PyCFunction)PyCurses_Init_Pair, METH_VARARGS}, - {"initscr", (PyCFunction)PyCurses_InitScr, METH_NOARGS}, - {"intrflush", (PyCFunction)PyCurses_IntrFlush, METH_VARARGS}, - {"isendwin", (PyCFunction)PyCurses_isendwin, METH_NOARGS}, -#ifdef HAVE_CURSES_IS_TERM_RESIZED - {"is_term_resized", (PyCFunction)PyCurses_Is_Term_Resized, METH_VARARGS}, -#endif - {"keyname", (PyCFunction)PyCurses_KeyName, METH_VARARGS}, - {"killchar", (PyCFunction)PyCurses_KillChar, METH_NOARGS}, - {"longname", (PyCFunction)PyCurses_longname, METH_NOARGS}, - {"meta", (PyCFunction)PyCurses_Meta, METH_VARARGS}, -#ifdef NCURSES_MOUSE_VERSION - {"mouseinterval", (PyCFunction)PyCurses_MouseInterval, METH_VARARGS}, - {"mousemask", (PyCFunction)PyCurses_MouseMask, METH_VARARGS}, -#endif - {"napms", (PyCFunction)PyCurses_Napms, METH_VARARGS}, - {"newpad", (PyCFunction)PyCurses_NewPad, METH_VARARGS}, - {"newwin", (PyCFunction)PyCurses_NewWindow, METH_VARARGS}, - {"nl", (PyCFunction)PyCurses_nl, METH_VARARGS}, - {"nocbreak", (PyCFunction)PyCurses_nocbreak, METH_NOARGS}, - {"noecho", (PyCFunction)PyCurses_noecho, METH_NOARGS}, - {"nonl", (PyCFunction)PyCurses_nonl, METH_NOARGS}, - {"noqiflush", (PyCFunction)PyCurses_noqiflush, METH_NOARGS}, - {"noraw", (PyCFunction)PyCurses_noraw, METH_NOARGS}, - {"pair_content", (PyCFunction)PyCurses_Pair_Content, METH_VARARGS}, - {"pair_number", (PyCFunction)PyCurses_pair_number, METH_VARARGS}, - {"putp", (PyCFunction)PyCurses_Putp, METH_VARARGS}, - {"qiflush", (PyCFunction)PyCurses_QiFlush, METH_VARARGS}, - {"raw", (PyCFunction)PyCurses_raw, METH_VARARGS}, - {"reset_prog_mode", (PyCFunction)PyCurses_reset_prog_mode, METH_NOARGS}, - {"reset_shell_mode", (PyCFunction)PyCurses_reset_shell_mode, METH_NOARGS}, - {"resetty", (PyCFunction)PyCurses_resetty, METH_NOARGS}, -#ifdef HAVE_CURSES_RESIZETERM - {"resizeterm", (PyCFunction)PyCurses_ResizeTerm, METH_VARARGS}, -#endif -#ifdef HAVE_CURSES_RESIZE_TERM - {"resize_term", (PyCFunction)PyCurses_Resize_Term, METH_VARARGS}, -#endif - {"savetty", (PyCFunction)PyCurses_savetty, METH_NOARGS}, -#ifdef getsyx - {"setsyx", (PyCFunction)PyCurses_setsyx, METH_VARARGS}, -#endif - {"setupterm", (PyCFunction)PyCurses_setupterm, - METH_VARARGS|METH_KEYWORDS}, - {"start_color", (PyCFunction)PyCurses_Start_Color, METH_NOARGS}, - {"termattrs", (PyCFunction)PyCurses_termattrs, METH_NOARGS}, - {"termname", (PyCFunction)PyCurses_termname, METH_NOARGS}, - {"tigetflag", (PyCFunction)PyCurses_tigetflag, METH_VARARGS}, - {"tigetnum", (PyCFunction)PyCurses_tigetnum, METH_VARARGS}, - {"tigetstr", (PyCFunction)PyCurses_tigetstr, METH_VARARGS}, - {"tparm", (PyCFunction)PyCurses_tparm, METH_VARARGS}, -#ifdef HAVE_CURSES_TYPEAHEAD - {"typeahead", (PyCFunction)PyCurses_TypeAhead, METH_VARARGS}, -#endif - {"unctrl", (PyCFunction)PyCurses_UnCtrl, METH_VARARGS}, - {"ungetch", (PyCFunction)PyCurses_UngetCh, METH_VARARGS}, -#if defined(HAVE_CURSES_RESIZETERM) || defined(HAVE_CURSES_RESIZE_TERM) - {"update_lines_cols", (PyCFunction)PyCurses_update_lines_cols, METH_NOARGS}, -#endif -#ifdef HAVE_NCURSESW - {"unget_wch", (PyCFunction)PyCurses_Unget_Wch, METH_VARARGS}, -#endif -#ifdef HAVE_CURSES_USE_ENV - {"use_env", (PyCFunction)PyCurses_Use_Env, METH_VARARGS}, -#endif -#ifndef STRICT_SYSV_CURSES - {"use_default_colors", (PyCFunction)PyCurses_Use_Default_Colors, METH_NOARGS}, -#endif - {NULL, NULL} /* sentinel */ -}; - -/* Initialization function for the module */ - - -static struct PyModuleDef _cursesmodule = { - PyModuleDef_HEAD_INIT, - "_curses", - NULL, - -1, - PyCurses_methods, - NULL, - NULL, - NULL, - NULL -}; - -PyMODINIT_FUNC -PyInit__curses(void) -{ - PyObject *m, *d, *v, *c_api_object; - static void *PyCurses_API[PyCurses_API_pointers]; - - /* Initialize object type */ - if (PyType_Ready(&PyCursesWindow_Type) < 0) - return NULL; - - /* Initialize the C API pointer array */ - PyCurses_API[0] = (void *)&PyCursesWindow_Type; - PyCurses_API[1] = (void *)func_PyCursesSetupTermCalled; - PyCurses_API[2] = (void *)func_PyCursesInitialised; - PyCurses_API[3] = (void *)func_PyCursesInitialisedColor; - - /* Create the module and add the functions */ - m = PyModule_Create(&_cursesmodule); - if (m == NULL) - return NULL; - - /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - if (d == NULL) - return NULL; - ModDict = d; /* For PyCurses_InitScr to use later */ - - /* Add a capsule for the C API */ - c_api_object = PyCapsule_New(PyCurses_API, PyCurses_CAPSULE_NAME, NULL); - PyDict_SetItemString(d, "_C_API", c_api_object); - Py_DECREF(c_api_object); - - /* For exception curses.error */ - PyCursesError = PyErr_NewException("_curses.error", NULL, NULL); - PyDict_SetItemString(d, "error", PyCursesError); - - /* Make the version available */ - v = PyBytes_FromString(PyCursesVersion); - PyDict_SetItemString(d, "version", v); - PyDict_SetItemString(d, "__version__", v); - Py_DECREF(v); - - SetDictInt("ERR", ERR); - SetDictInt("OK", OK); - - /* Here are some attributes you can add to chars to print */ - - SetDictInt("A_ATTRIBUTES", A_ATTRIBUTES); - SetDictInt("A_NORMAL", A_NORMAL); - SetDictInt("A_STANDOUT", A_STANDOUT); - SetDictInt("A_UNDERLINE", A_UNDERLINE); - SetDictInt("A_REVERSE", A_REVERSE); - SetDictInt("A_BLINK", A_BLINK); - SetDictInt("A_DIM", A_DIM); - SetDictInt("A_BOLD", A_BOLD); - SetDictInt("A_ALTCHARSET", A_ALTCHARSET); - SetDictInt("A_INVIS", A_INVIS); - SetDictInt("A_PROTECT", A_PROTECT); - SetDictInt("A_CHARTEXT", A_CHARTEXT); - SetDictInt("A_COLOR", A_COLOR); - - /* The following are never available with strict SYSV curses */ -#ifdef A_HORIZONTAL - SetDictInt("A_HORIZONTAL", A_HORIZONTAL); -#endif -#ifdef A_LEFT - SetDictInt("A_LEFT", A_LEFT); -#endif -#ifdef A_LOW - SetDictInt("A_LOW", A_LOW); -#endif -#ifdef A_RIGHT - SetDictInt("A_RIGHT", A_RIGHT); -#endif -#ifdef A_TOP - SetDictInt("A_TOP", A_TOP); -#endif -#ifdef A_VERTICAL - SetDictInt("A_VERTICAL", A_VERTICAL); -#endif - - SetDictInt("COLOR_BLACK", COLOR_BLACK); - SetDictInt("COLOR_RED", COLOR_RED); - SetDictInt("COLOR_GREEN", COLOR_GREEN); - SetDictInt("COLOR_YELLOW", COLOR_YELLOW); - SetDictInt("COLOR_BLUE", COLOR_BLUE); - SetDictInt("COLOR_MAGENTA", COLOR_MAGENTA); - SetDictInt("COLOR_CYAN", COLOR_CYAN); - SetDictInt("COLOR_WHITE", COLOR_WHITE); - -#ifdef NCURSES_MOUSE_VERSION - /* Mouse-related constants */ - SetDictInt("BUTTON1_PRESSED", BUTTON1_PRESSED); - SetDictInt("BUTTON1_RELEASED", BUTTON1_RELEASED); - SetDictInt("BUTTON1_CLICKED", BUTTON1_CLICKED); - SetDictInt("BUTTON1_DOUBLE_CLICKED", BUTTON1_DOUBLE_CLICKED); - SetDictInt("BUTTON1_TRIPLE_CLICKED", BUTTON1_TRIPLE_CLICKED); - - SetDictInt("BUTTON2_PRESSED", BUTTON2_PRESSED); - SetDictInt("BUTTON2_RELEASED", BUTTON2_RELEASED); - SetDictInt("BUTTON2_CLICKED", BUTTON2_CLICKED); - SetDictInt("BUTTON2_DOUBLE_CLICKED", BUTTON2_DOUBLE_CLICKED); - SetDictInt("BUTTON2_TRIPLE_CLICKED", BUTTON2_TRIPLE_CLICKED); - - SetDictInt("BUTTON3_PRESSED", BUTTON3_PRESSED); - SetDictInt("BUTTON3_RELEASED", BUTTON3_RELEASED); - SetDictInt("BUTTON3_CLICKED", BUTTON3_CLICKED); - SetDictInt("BUTTON3_DOUBLE_CLICKED", BUTTON3_DOUBLE_CLICKED); - SetDictInt("BUTTON3_TRIPLE_CLICKED", BUTTON3_TRIPLE_CLICKED); - - SetDictInt("BUTTON4_PRESSED", BUTTON4_PRESSED); - SetDictInt("BUTTON4_RELEASED", BUTTON4_RELEASED); - SetDictInt("BUTTON4_CLICKED", BUTTON4_CLICKED); - SetDictInt("BUTTON4_DOUBLE_CLICKED", BUTTON4_DOUBLE_CLICKED); - SetDictInt("BUTTON4_TRIPLE_CLICKED", BUTTON4_TRIPLE_CLICKED); - - SetDictInt("BUTTON_SHIFT", BUTTON_SHIFT); - SetDictInt("BUTTON_CTRL", BUTTON_CTRL); - SetDictInt("BUTTON_ALT", BUTTON_ALT); - - SetDictInt("ALL_MOUSE_EVENTS", ALL_MOUSE_EVENTS); - SetDictInt("REPORT_MOUSE_POSITION", REPORT_MOUSE_POSITION); -#endif - /* Now set everything up for KEY_ variables */ - { - int key; - char *key_n; - char *key_n2; - for (key=KEY_MIN;key < KEY_MAX; key++) { - key_n = (char *)keyname(key); - if (key_n == NULL || strcmp(key_n,"UNKNOWN KEY")==0) - continue; - if (strncmp(key_n,"KEY_F(",6)==0) { - char *p1, *p2; - key_n2 = PyMem_Malloc(strlen(key_n)+1); - if (!key_n2) { - PyErr_NoMemory(); - break; - } - p1 = key_n; - p2 = key_n2; - while (*p1) { - if (*p1 != '(' && *p1 != ')') { - *p2 = *p1; - p2++; - } - p1++; - } - *p2 = (char)0; - } else - key_n2 = key_n; - SetDictInt(key_n2,key); - if (key_n2 != key_n) - PyMem_Free(key_n2); - } - SetDictInt("KEY_MIN", KEY_MIN); - SetDictInt("KEY_MAX", KEY_MAX); - } - return m; -} diff --git a/third_party/python/Modules/_datetimemodule.c b/third_party/python/Modules/_datetimemodule.c index 79dc63e68..a2e95eed2 100644 --- a/third_party/python/Modules/_datetimemodule.c +++ b/third_party/python/Modules/_datetimemodule.c @@ -6041,6 +6041,11 @@ PyInit__datetime(void) return m; } +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__datetime = { + "_datetime", + PyInit__datetime, +}; + /* --------------------------------------------------------------------------- Some time zone algebra. For a datetime x, let x.n = x stripped of its timezone -- its naive time. diff --git a/third_party/python/Modules/_decimal/_decimal.c b/third_party/python/Modules/_decimal/_decimal.c index 548225857..c05b70410 100644 --- a/third_party/python/Modules/_decimal/_decimal.c +++ b/third_party/python/Modules/_decimal/_decimal.c @@ -5992,7 +5992,7 @@ error: return NULL; /* GCOV_NOT_REACHED */ } -_Section(".rodata.pytab") struct _inittab _PyImport_Inittab__decimal = { - "_decimal", +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__decimal = { + "_decimal", PyInit__decimal, }; diff --git a/third_party/python/Modules/_elementtree.c b/third_party/python/Modules/_elementtree.c index dc60a376c..a1c9372ad 100644 --- a/third_party/python/Modules/_elementtree.c +++ b/third_party/python/Modules/_elementtree.c @@ -4091,3 +4091,8 @@ PyInit__elementtree(void) return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__elementtree = { + "_elementtree", + PyInit__elementtree, +}; diff --git a/third_party/python/Modules/_functoolsmodule.c b/third_party/python/Modules/_functoolsmodule.c index 1617ed041..47928a175 100644 --- a/third_party/python/Modules/_functoolsmodule.c +++ b/third_party/python/Modules/_functoolsmodule.c @@ -10,6 +10,7 @@ #include "third_party/python/Include/classobject.h" #include "third_party/python/Include/descrobject.h" #include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/object.h" diff --git a/third_party/python/Modules/_hashopenssl.c b/third_party/python/Modules/_hashmbedtls.c similarity index 88% rename from third_party/python/Modules/_hashopenssl.c rename to third_party/python/Modules/_hashmbedtls.c index 89712aaf2..292d25fdb 100644 --- a/third_party/python/Modules/_hashopenssl.c +++ b/third_party/python/Modules/_hashmbedtls.c @@ -5,8 +5,10 @@ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ #define PY_SSIZE_T_CLEAN +#include "third_party/mbedtls/error.h" #include "third_party/mbedtls/md.h" #include "third_party/python/Include/Python.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/pystrhex.h" #include "third_party/python/Include/structmember.h" #include "third_party/python/Include/yoink.h" @@ -21,15 +23,15 @@ PYTHON_PROVIDE("_hashlib.__name__"); PYTHON_PROVIDE("_hashlib.__package__"); PYTHON_PROVIDE("_hashlib.__spec__"); PYTHON_PROVIDE("_hashlib.new"); -PYTHON_PROVIDE("_hashlib.openssl_md5"); -PYTHON_PROVIDE("_hashlib.openssl_md_meth_names"); -PYTHON_PROVIDE("_hashlib.openssl_sha1"); -PYTHON_PROVIDE("_hashlib.openssl_sha224"); -PYTHON_PROVIDE("_hashlib.openssl_sha256"); -PYTHON_PROVIDE("_hashlib.openssl_sha384"); -PYTHON_PROVIDE("_hashlib.openssl_sha512"); +PYTHON_PROVIDE("_hashlib.mbedtls_md5"); +PYTHON_PROVIDE("_hashlib.mbedtls_md_meth_names"); +PYTHON_PROVIDE("_hashlib.mbedtls_sha1"); +PYTHON_PROVIDE("_hashlib.mbedtls_sha224"); +PYTHON_PROVIDE("_hashlib.mbedtls_sha256"); +PYTHON_PROVIDE("_hashlib.mbedtls_sha384"); +PYTHON_PROVIDE("_hashlib.mbedtls_sha512"); -#include "third_party/python/Modules/clinic/_hashopenssl.inc" +#include "third_party/python/Modules/clinic/_hashmbedtls.inc" /*[clinic input] module _hashlib [clinic start generated code]*/ @@ -51,49 +53,26 @@ typedef struct { } EVPobject; static PyTypeObject EVPtype; -static PyObject *CONST_md5_name_obj; -static PyObject *CONST_sha1_name_obj; -static PyObject *CONST_sha224_name_obj; -static PyObject *CONST_sha256_name_obj; -static PyObject *CONST_sha384_name_obj; -static PyObject *CONST_sha512_name_obj; #define DEFINE_CONSTS_FOR_NEW(Name) \ static PyObject *CONST_ ## Name ## _name_obj = NULL; \ - static mbedtls_md_context_t *CONST_new_ ## Name ## _ctx_p = NULL; + static mbedtls_md_context_t *CONST_new_ ## Name ## _ctx_p = NULL -DEFINE_CONSTS_FOR_NEW(md5) -DEFINE_CONSTS_FOR_NEW(sha1) -DEFINE_CONSTS_FOR_NEW(sha224) -DEFINE_CONSTS_FOR_NEW(sha256) -DEFINE_CONSTS_FOR_NEW(sha384) -DEFINE_CONSTS_FOR_NEW(sha512) +DEFINE_CONSTS_FOR_NEW(md5); +DEFINE_CONSTS_FOR_NEW(sha1); +DEFINE_CONSTS_FOR_NEW(sha224); +DEFINE_CONSTS_FOR_NEW(sha256); +DEFINE_CONSTS_FOR_NEW(sha384); +DEFINE_CONSTS_FOR_NEW(sha512); +DEFINE_CONSTS_FOR_NEW(blake2b256); /* LCOV_EXCL_START */ static PyObject * -_setException(PyObject *exc) +_setException(PyObject *exc, int rc) { - /* unsigned long errcode; */ - /* const char *lib, *func, *reason; */ - /* errcode = ERR_peek_last_error(); */ - /* if (!errcode) { */ - /* PyErr_SetString(exc, "unknown reasons"); */ - /* return NULL; */ - /* } */ - /* ERR_clear_error(); */ - /* lib = ERR_lib_error_string(errcode); */ - /* func = ERR_func_error_string(errcode); */ - /* reason = ERR_reason_error_string(errcode); */ - /* if (lib && func) { */ - /* PyErr_Format(exc, "[%s: %s] %s", lib, func, reason); */ - /* } */ - /* else if (lib) { */ - /* PyErr_Format(exc, "[%s] %s", lib, reason); */ - /* } */ - /* else { */ - /* PyErr_SetString(exc, reason); */ - /* } */ - PyErr_SetString(exc, "failhouse"); + char b[128]; + mbedtls_strerror(rc, b, sizeof(b)); + PyErr_SetString(exc, b); return NULL; } /* LCOV_EXCL_STOP */ @@ -122,6 +101,7 @@ newEVPobject(PyObject *name) static void EVP_hash(EVPobject *self, const void *vp, Py_ssize_t len) { + int rc; unsigned int process; const unsigned char *cp = (const unsigned char *)vp; while (0 < len) { @@ -129,8 +109,8 @@ EVP_hash(EVPobject *self, const void *vp, Py_ssize_t len) process = MUNCH_SIZE; else process = Py_SAFE_DOWNCAST(len, Py_ssize_t, unsigned int); - if (!mbedtls_md_update(self->ctx, (const void*)cp, process)) { - _setException(PyExc_ValueError); + if ((rc = mbedtls_md_update(self->ctx, (const void*)cp, process))) { + _setException(PyExc_ValueError, rc); break; } len -= process; @@ -156,12 +136,11 @@ EVP_dealloc(EVPobject *self) static int locked_mbedtls_md_clone(mbedtls_md_context_t *new_ctx_p, EVPobject *self) { - int result; + int rc; ENTER_HASHLIB(self); - result = mbedtls_md_clone(new_ctx_p, self->ctx); - result = 0; + rc = mbedtls_md_clone(new_ctx_p, self->ctx); LEAVE_HASHLIB(self); - return result; + return rc; } /* External methods for a hash object */ @@ -171,11 +150,12 @@ PyDoc_STRVAR(EVP_copy__doc__, "Return a copy of the hash object."); static PyObject * EVP_copy(EVPobject *self, PyObject *unused) { + int rc; EVPobject *newobj; if ( (newobj = newEVPobject(self->name))==NULL) return NULL; - if (!locked_mbedtls_md_clone(newobj->ctx, self)) { - return _setException(PyExc_ValueError); + if ((rc = locked_mbedtls_md_clone(newobj->ctx, self))) { + return _setException(PyExc_ValueError, rc); } return (PyObject *)newobj; } @@ -186,6 +166,7 @@ PyDoc_STRVAR(EVP_digest__doc__, static PyObject * EVP_digest(EVPobject *self, PyObject *unused) { + int rc; unsigned char digest[MBEDTLS_MD_MAX_SIZE]; mbedtls_md_context_t *temp_ctx; PyObject *retval; @@ -195,12 +176,12 @@ EVP_digest(EVPobject *self, PyObject *unused) PyErr_NoMemory(); return NULL; } - if (!locked_mbedtls_md_clone(temp_ctx, self)) { - return _setException(PyExc_ValueError); + if ((rc = locked_mbedtls_md_clone(temp_ctx, self))) { + return _setException(PyExc_ValueError, rc); } digest_size = mbedtls_md_get_size(temp_ctx->md_info); - if (!mbedtls_md_finish(temp_ctx, digest)) { - _setException(PyExc_ValueError); + if ((rc = mbedtls_md_finish(temp_ctx, digest))) { + _setException(PyExc_ValueError, rc); return NULL; } retval = PyBytes_FromStringAndSize((const char *)digest, digest_size); @@ -214,6 +195,7 @@ PyDoc_STRVAR(EVP_hexdigest__doc__, static PyObject * EVP_hexdigest(EVPobject *self, PyObject *unused) { + int rc; unsigned char digest[MBEDTLS_MD_MAX_SIZE]; mbedtls_md_context_t *temp_ctx; unsigned int digest_size; @@ -223,12 +205,12 @@ EVP_hexdigest(EVPobject *self, PyObject *unused) return NULL; } /* Get the raw (binary) digest value */ - if (!locked_mbedtls_md_clone(temp_ctx, self)) { - return _setException(PyExc_ValueError); + if ((rc = locked_mbedtls_md_clone(temp_ctx, self))) { + return _setException(PyExc_ValueError, rc); } digest_size = mbedtls_md_get_size(temp_ctx->md_info); - if (!mbedtls_md_finish(temp_ctx, digest)) { - _setException(PyExc_ValueError); + if ((rc = mbedtls_md_finish(temp_ctx, digest))) { + _setException(PyExc_ValueError, rc); return NULL; } mbedtls_md_free(temp_ctx); @@ -432,6 +414,7 @@ EVPnew(PyObject *name_obj, const mbedtls_md_context_t *initial_ctx, const unsigned char *cp, Py_ssize_t len) { + int rc; EVPobject *self; if (!digest && !initial_ctx) { PyErr_SetString(PyExc_ValueError, "unsupported hash type"); @@ -442,8 +425,8 @@ EVPnew(PyObject *name_obj, if (initial_ctx) { mbedtls_md_clone(self->ctx, initial_ctx); } else { - if (!mbedtls_md_setup(self->ctx, digest, 0)) { - _setException(PyExc_ValueError); + if ((rc = mbedtls_md_setup(self->ctx, digest, 0))) { + _setException(PyExc_ValueError, rc); Py_DECREF(self); return NULL; } @@ -497,8 +480,8 @@ EVP_new(PyObject *self, PyObject *args, PyObject *kwdict) return ret_obj; } -#if (OPENSSL_VERSION_NUMBER >= 0x10000000 && !defined(OPENSSL_NO_HMAC) \ - && !defined(OPENSSL_NO_SHA)) +#if (MBEDTLS_VERSION_NUMBER >= 0x10000000 && !defined(MBEDTLS_NO_HMAC) \ + && !defined(MBEDTLS_NO_SHA)) #define PY_PBKDF2_HMAC 1 @@ -510,7 +493,7 @@ EVP_new(PyObject *self, PyObject *args, PyObject *kwdict) * more. The improved algorithm is not subject to a Denial-of-Service * vulnerability with overly large passwords. * - * Also OpenSSL < 1.0 don't provide PKCS5_PBKDF2_HMAC(), only + * Also Mbedtls < 1.0 don't provide PKCS5_PBKDF2_HMAC(), only * PKCS5_PBKDF2_SHA1. */ static int @@ -680,9 +663,9 @@ pbkdf2_hmac(PyObject *self, PyObject *args, PyObject *kwdict) #endif Py_END_ALLOW_THREADS - if (!retval) { + if (retval) { Py_CLEAR(key_obj); - _setException(PyExc_ValueError); + _setException(PyExc_ValueError, retval); goto end; } @@ -694,7 +677,7 @@ pbkdf2_hmac(PyObject *self, PyObject *args, PyObject *kwdict) #endif -#if OPENSSL_VERSION_NUMBER > 0x10100000L && !defined(OPENSSL_NO_SCRYPT) && !defined(LIBRESSL_VERSION_NUMBER) +#if MBEDTLS_VERSION_NUMBER > 0x10100000L && !defined(MBEDTLS_NO_SCRYPT) && !defined(LIBRESSL_VERSION_NUMBER) #define PY_SCRYPT 1 /* XXX: Parameters salt, n, r and p should be required keyword-only parameters. They are optional in the Argument Clinic declaration only due to a @@ -764,8 +747,8 @@ _hashlib_scrypt_impl(PyObject *module, Py_buffer *password, Py_buffer *salt, return NULL; } if (maxmem < 0 || maxmem > INT_MAX) { - /* OpenSSL 1.1.0 restricts maxmem to 32MB. It may change in the - future. The maxmem constant is private to OpenSSL. */ + /* Mbedtls 1.1.0 restricts maxmem to 32MB. It may change in the + future. The maxmem constant is private to Mbedtls. */ PyErr_Format(PyExc_ValueError, "maxmem must be positive and smaller than %d", INT_MAX); @@ -777,7 +760,7 @@ _hashlib_scrypt_impl(PyObject *module, Py_buffer *password, Py_buffer *salt, INT_MAX); return NULL; } - /* let OpenSSL validate the rest */ + /* let Mbedtls validate the rest */ retval = EVP_PBE_scrypt(NULL, 0, NULL, 0, n, r, p, maxmem, NULL, 0); if (!retval) { /* sorry, can't do much better */ @@ -835,6 +818,7 @@ generate_hash_name_list(void) static PyObject * \ EVP_new_ ## NAME (PyObject *self, PyObject *args) \ { \ + int rc; \ PyObject *data_obj = NULL; \ Py_buffer view = { 0 }; \ PyObject *ret_obj; \ @@ -845,9 +829,10 @@ generate_hash_name_list(void) \ if (CONST_new_ ## NAME ## _ctx_p == NULL) { \ mbedtls_md_context_t *ctx_p = calloc(1, sizeof(mbedtls_md_context_t)); \ + rc = MBEDTLS_ERR_MD_FEATURE_UNAVAILABLE; \ if (!mbedtls_md_info_from_string(#NAME) || \ - !mbedtls_md_setup(ctx_p, mbedtls_md_info_from_string(#NAME), 0)) { \ - _setException(PyExc_ValueError); \ + (rc = mbedtls_md_setup(ctx_p, mbedtls_md_info_from_string(#NAME), 0))) { \ + _setException(PyExc_ValueError, rc); \ mbedtls_md_free(ctx_p); \ return NULL; \ } \ @@ -871,12 +856,12 @@ generate_hash_name_list(void) /* a PyMethodDef structure for the constructor */ #define CONSTRUCTOR_METH_DEF(NAME) \ - {"openssl_" #NAME, (PyCFunction)EVP_new_ ## NAME, METH_VARARGS, \ + {"mbedtls_" #NAME, (PyCFunction)EVP_new_ ## NAME, METH_VARARGS, \ PyDoc_STR("Returns a " #NAME \ " hash object; optionally initialized with a string") \ } -/* used in the init function to setup a constructor: initialize OpenSSL +/* used in the init function to setup a constructor: initialize Mbedtls constructor constants if they haven't been initialized already. */ #define INIT_CONSTRUCTOR_CONSTANTS(NAME) \ if (CONST_ ## NAME ## _name_obj == NULL) { \ @@ -889,6 +874,7 @@ GEN_CONSTRUCTOR(sha224) GEN_CONSTRUCTOR(sha256) GEN_CONSTRUCTOR(sha384) GEN_CONSTRUCTOR(sha512) +GEN_CONSTRUCTOR(blake2b256) /* List of functions exported by this module */ @@ -905,6 +891,7 @@ static struct PyMethodDef EVP_functions[] = { CONSTRUCTOR_METH_DEF(sha256), CONSTRUCTOR_METH_DEF(sha384), CONSTRUCTOR_METH_DEF(sha512), + CONSTRUCTOR_METH_DEF(blake2b256), {NULL, NULL} /* Sentinel */ }; @@ -923,8 +910,8 @@ static struct PyModuleDef _hashlibmodule = { PyMODINIT_FUNC PyInit__hashlib(void) { - PyObject *m, *openssl_md_meth_names; - /* TODO build EVP_functions openssl_* entries dynamically based + PyObject *m, *mbedtls_md_meth_names; + /* TODO build EVP_functions mbedtls_* entries dynamically based * on what hashes are supported rather than listing many * but having some be unsupported. Only init appropriate * constants. */ @@ -934,12 +921,12 @@ PyInit__hashlib(void) m = PyModule_Create(&_hashlibmodule); if (m == NULL) return NULL; - openssl_md_meth_names = generate_hash_name_list(); - if (openssl_md_meth_names == NULL) { + mbedtls_md_meth_names = generate_hash_name_list(); + if (mbedtls_md_meth_names == NULL) { Py_DECREF(m); return NULL; } - if (PyModule_AddObject(m, "openssl_md_meth_names", openssl_md_meth_names)) { + if (PyModule_AddObject(m, "mbedtls_md_meth_names", mbedtls_md_meth_names)) { Py_DECREF(m); return NULL; } @@ -952,5 +939,11 @@ PyInit__hashlib(void) INIT_CONSTRUCTOR_CONSTANTS(sha256) INIT_CONSTRUCTOR_CONSTANTS(sha384) INIT_CONSTRUCTOR_CONSTANTS(sha512) + INIT_CONSTRUCTOR_CONSTANTS(blake2b256) return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__hashlib = { + "_hashlib", + PyInit__hashlib, +}; diff --git a/third_party/python/Modules/_heapqmodule.c b/third_party/python/Modules/_heapqmodule.c index 42bb59082..11de7cafe 100644 --- a/third_party/python/Modules/_heapqmodule.c +++ b/third_party/python/Modules/_heapqmodule.c @@ -5,6 +5,7 @@ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/assert.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/listobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/pyerrors.h" @@ -683,4 +684,3 @@ PyInit__heapq(void) PyModule_AddObject(m, "__about__", about); return m; } - diff --git a/third_party/python/Modules/_json.c b/third_party/python/Modules/_json.c index 344013726..ac66eac41 100644 --- a/third_party/python/Modules/_json.c +++ b/third_party/python/Modules/_json.c @@ -1,3 +1,9 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Python 3 │ +│ https://docs.python.org/3/license.html │ +╚─────────────────────────────────────────────────────────────────────────────*/ #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/accu.h" #include "third_party/python/Include/boolobject.h" @@ -1971,3 +1977,8 @@ PyInit__json(void) Py_DECREF(m); return NULL; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__json = { + "_json", + PyInit__json, +}; diff --git a/third_party/python/Modules/_localemodule.c b/third_party/python/Modules/_localemodule.c index 04385b892..b4c438265 100644 --- a/third_party/python/Modules/_localemodule.c +++ b/third_party/python/Modules/_localemodule.c @@ -5,9 +5,11 @@ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ #define PY_SSIZE_T_CLEAN +#include "libc/unicode/langinfo.h" #include "libc/unicode/locale.h" #include "third_party/python/Include/dictobject.h" #include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/listobject.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" diff --git a/third_party/python/Modules/_lsprof.c b/third_party/python/Modules/_lsprof.c index 4e564f09e..a58ed47f2 100644 --- a/third_party/python/Modules/_lsprof.c +++ b/third_party/python/Modules/_lsprof.c @@ -5,6 +5,7 @@ #include "third_party/python/Include/dictobject.h" #include "third_party/python/Include/floatobject.h" #include "third_party/python/Include/frameobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/objimpl.h" @@ -900,3 +901,8 @@ PyInit__lsprof(void) initialized = 1; return module; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__lsprof = { + "_lsprof", + PyInit__lsprof, +}; diff --git a/third_party/python/Modules/_multiprocessing/multiprocessing.c b/third_party/python/Modules/_multiprocessing/multiprocessing.c index f75e7c352..f4358296f 100644 --- a/third_party/python/Modules/_multiprocessing/multiprocessing.c +++ b/third_party/python/Modules/_multiprocessing/multiprocessing.c @@ -224,3 +224,8 @@ PyInit__multiprocessing(void) return module; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__multiprocessing = { + "_multiprocessing", + PyInit__multiprocessing, +}; diff --git a/third_party/python/Modules/_opcode.c b/third_party/python/Modules/_opcode.c index 743e41a59..6275546b1 100644 --- a/third_party/python/Modules/_opcode.c +++ b/third_party/python/Modules/_opcode.c @@ -5,6 +5,7 @@ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "third_party/python/Include/compile.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/object.h" @@ -92,3 +93,8 @@ PyInit__opcode(void) { return PyModule_Create(&opcodemodule); } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__opcode = { + "_opcode", + PyInit__opcode, +}; diff --git a/third_party/python/Modules/_pickle.c b/third_party/python/Modules/_pickle.c index 9a620896b..aa815047e 100644 --- a/third_party/python/Modules/_pickle.c +++ b/third_party/python/Modules/_pickle.c @@ -44,6 +44,8 @@ PYTHON_PROVIDE("_pickle.dumps"); PYTHON_PROVIDE("_pickle.load"); PYTHON_PROVIDE("_pickle.loads"); +PYTHON_YOINK("encodings.ascii"); + PyDoc_STRVAR(pickle_module_doc, "Optimized C implementation for the Python pickle module."); @@ -7475,3 +7477,8 @@ PyInit__pickle(void) return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__pickle = { + "_pickle", + PyInit__pickle, +}; diff --git a/third_party/python/Modules/_posixsubprocess.c b/third_party/python/Modules/_posixsubprocess.c index 45a5fa376..3dbc042d2 100644 --- a/third_party/python/Modules/_posixsubprocess.c +++ b/third_party/python/Modules/_posixsubprocess.c @@ -724,3 +724,8 @@ PyInit__posixsubprocess(void) { return PyModule_Create(&_posixsubprocessmodule); } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__posixsubprocess = { + "_posixsubprocess", + PyInit__posixsubprocess, +}; diff --git a/third_party/python/Modules/_randommodule.c b/third_party/python/Modules/_randommodule.c index 050ef77b4..4e578e5fd 100644 --- a/third_party/python/Modules/_randommodule.c +++ b/third_party/python/Modules/_randommodule.c @@ -6,6 +6,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/calls.h" #include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/objimpl.h" @@ -561,3 +562,8 @@ PyInit__random(void) PyModule_AddObject(m, "Random", (PyObject *)&Random_Type); return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__random = { + "_random", + PyInit__random, +}; diff --git a/third_party/python/Modules/_sha3.c b/third_party/python/Modules/_sha3.c index 99cf69184..04ffcb53d 100644 --- a/third_party/python/Modules/_sha3.c +++ b/third_party/python/Modules/_sha3.c @@ -7,17 +7,33 @@ #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/bytesobject.h" #include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/object.h" #include "third_party/python/Include/objimpl.h" #include "third_party/python/Include/pyerrors.h" #include "third_party/python/Include/pystrhex.h" +#include "third_party/python/Include/yoink.h" + +PYTHON_PROVIDE("_sha3"); +PYTHON_PROVIDE("_sha3.__doc__"); +PYTHON_PROVIDE("_sha3.__loader__"); +PYTHON_PROVIDE("_sha3.__name__"); +PYTHON_PROVIDE("_sha3.__package__"); +PYTHON_PROVIDE("_sha3.__spec__"); +PYTHON_PROVIDE("_sha3.implementation"); +PYTHON_PROVIDE("_sha3.keccakopt"); +PYTHON_PROVIDE("_sha3.sha3_224"); +PYTHON_PROVIDE("_sha3.sha3_256"); +PYTHON_PROVIDE("_sha3.sha3_384"); +PYTHON_PROVIDE("_sha3.sha3_512"); +PYTHON_PROVIDE("_sha3.shake_128"); +PYTHON_PROVIDE("_sha3.shake_256"); /* Ran preprocessor on working build, because spaghetti structure of upstream Python 3.6 source code was unnaceptably incomprehensible -TODO(jart): Find SHA3 that isn't written in a laugh out loud way! */ typedef enum { SUCCESS = 0, FAIL = 1, BAD_HASHLEN = 2 } HashReturn; @@ -35,15 +51,15 @@ typedef struct { unsigned char delimitedSuffix; } Keccak_HashInstance; -static const uint64_t KeccakF1600RoundConstants[24] = { - 0x0000000000000001ULL, 0x0000000000008082ULL, 0x800000000000808aULL, - 0x8000000080008000ULL, 0x000000000000808bULL, 0x0000000080000001ULL, - 0x8000000080008081ULL, 0x8000000000008009ULL, 0x000000000000008aULL, - 0x0000000000000088ULL, 0x0000000080008009ULL, 0x000000008000000aULL, - 0x000000008000808bULL, 0x800000000000008bULL, 0x8000000000008089ULL, - 0x8000000000008003ULL, 0x8000000000008002ULL, 0x8000000000000080ULL, - 0x000000000000800aULL, 0x800000008000000aULL, 0x8000000080008081ULL, - 0x8000000000008080ULL, 0x0000000080000001ULL, 0x8000000080008008ULL, +static const uint64_t kKeccakf[24] = { + 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, + 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, + 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, + 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, + 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, + 0x8000000000008003, 0x8000000000008002, 0x8000000000000080, + 0x000000000000800a, 0x800000008000000a, 0x8000000080008081, + 0x8000000000008080, 0x0000000080000001, 0x8000000080008008, }; static void _PySHA3_KeccakP1600_Initialize(void *state) { @@ -203,6 +219,8 @@ static void _PySHA3_KeccakP1600_OverwriteWithZeroes(void *state, } static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { + uint64_t Ca, Ce, Ci, Co, Cu; + uint64_t Da, De, Di, Do, Du; uint64_t Aba, Abe, Abi, Abo, Abu; uint64_t Aga, Age, Agi, Ago, Agu; uint64_t Aka, Ake, Aki, Ako, Aku; @@ -213,8 +231,6 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { uint64_t Bka, Bke, Bki, Bko, Bku; uint64_t Bma, Bme, Bmi, Bmo, Bmu; uint64_t Bsa, Bse, Bsi, Bso, Bsu; - uint64_t Ca, Ce, Ci, Co, Cu; - uint64_t Da, De, Di, Do, Du; uint64_t Eba, Ebe, Ebi, Ebo, Ebu; uint64_t Ega, Ege, Egi, Ego, Egu; uint64_t Eka, Eke, Eki, Eko, Eku; @@ -267,7 +283,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[0]; + Eba ^= kKeccakf[0]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -373,7 +389,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[1]; + Aba ^= kKeccakf[1]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -479,7 +495,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[2]; + Eba ^= kKeccakf[2]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -585,7 +601,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[3]; + Aba ^= kKeccakf[3]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -691,7 +707,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[4]; + Eba ^= kKeccakf[4]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -797,7 +813,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[5]; + Aba ^= kKeccakf[5]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -903,7 +919,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[6]; + Eba ^= kKeccakf[6]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -1009,7 +1025,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[7]; + Aba ^= kKeccakf[7]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -1115,7 +1131,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[8]; + Eba ^= kKeccakf[8]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -1221,7 +1237,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[9]; + Aba ^= kKeccakf[9]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -1327,7 +1343,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[10]; + Eba ^= kKeccakf[10]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -1433,7 +1449,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[11]; + Aba ^= kKeccakf[11]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -1539,7 +1555,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[12]; + Eba ^= kKeccakf[12]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -1645,7 +1661,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[13]; + Aba ^= kKeccakf[13]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -1751,7 +1767,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[14]; + Eba ^= kKeccakf[14]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -1857,7 +1873,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[15]; + Aba ^= kKeccakf[15]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -1963,7 +1979,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[16]; + Eba ^= kKeccakf[16]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -2069,7 +2085,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[17]; + Aba ^= kKeccakf[17]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -2175,7 +2191,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[18]; + Eba ^= kKeccakf[18]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -2281,7 +2297,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[19]; + Aba ^= kKeccakf[19]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -2387,7 +2403,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[20]; + Eba ^= kKeccakf[20]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -2493,7 +2509,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[21]; + Aba ^= kKeccakf[21]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -2599,7 +2615,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[22]; + Eba ^= kKeccakf[22]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -2705,7 +2721,7 @@ static void _PySHA3_KeccakP1600_Permute_24rounds(void *state) { Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[23]; + Aba ^= kKeccakf[23]; Abe = Bbe ^ ((~Bbi) | Bbo); Abi = Bbi ^ (Bbo & Bbu); Abo = Bbo ^ (Bbu | Bba); @@ -2862,7 +2878,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) { Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[12]; + Eba ^= kKeccakf[12]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -2968,7 +2984,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) { Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[13]; + Aba ^= kKeccakf[13]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -3074,7 +3090,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) { Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[14]; + Eba ^= kKeccakf[14]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -3180,7 +3196,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) { Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[15]; + Aba ^= kKeccakf[15]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -3286,7 +3302,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) { Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[16]; + Eba ^= kKeccakf[16]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -3392,7 +3408,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) { Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[17]; + Aba ^= kKeccakf[17]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -3498,7 +3514,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) { Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[18]; + Eba ^= kKeccakf[18]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -3604,7 +3620,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) { Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[19]; + Aba ^= kKeccakf[19]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -3710,7 +3726,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) { Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[20]; + Eba ^= kKeccakf[20]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -3816,7 +3832,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) { Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[21]; + Aba ^= kKeccakf[21]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -3922,7 +3938,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) { Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[22]; + Eba ^= kKeccakf[22]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -4028,7 +4044,7 @@ static void _PySHA3_KeccakP1600_Permute_12rounds(void *state) { Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[23]; + Aba ^= kKeccakf[23]; Abe = Bbe ^ ((~Bbi) | Bbo); Abi = Bbi ^ (Bbo & Bbu); Abo = Bbo ^ (Bbu | Bba); @@ -4423,7 +4439,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[0]; + Eba ^= kKeccakf[0]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -4529,7 +4545,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[1]; + Aba ^= kKeccakf[1]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -4635,7 +4651,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[2]; + Eba ^= kKeccakf[2]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -4741,7 +4757,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[3]; + Aba ^= kKeccakf[3]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -4847,7 +4863,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[4]; + Eba ^= kKeccakf[4]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -4953,7 +4969,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[5]; + Aba ^= kKeccakf[5]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -5059,7 +5075,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[6]; + Eba ^= kKeccakf[6]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -5165,7 +5181,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[7]; + Aba ^= kKeccakf[7]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -5271,7 +5287,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[8]; + Eba ^= kKeccakf[8]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -5377,7 +5393,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[9]; + Aba ^= kKeccakf[9]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -5483,7 +5499,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[10]; + Eba ^= kKeccakf[10]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -5589,7 +5605,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[11]; + Aba ^= kKeccakf[11]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -5695,7 +5711,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[12]; + Eba ^= kKeccakf[12]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -5801,7 +5817,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[13]; + Aba ^= kKeccakf[13]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -5907,7 +5923,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[14]; + Eba ^= kKeccakf[14]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -6013,7 +6029,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[15]; + Aba ^= kKeccakf[15]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -6119,7 +6135,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[16]; + Eba ^= kKeccakf[16]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -6225,7 +6241,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[17]; + Aba ^= kKeccakf[17]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -6331,7 +6347,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[18]; + Eba ^= kKeccakf[18]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -6437,7 +6453,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[19]; + Aba ^= kKeccakf[19]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -6543,7 +6559,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[20]; + Eba ^= kKeccakf[20]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -6649,7 +6665,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[21]; + Aba ^= kKeccakf[21]; Ca = Aba; Abe = Bbe ^ ((~Bbi) | Bbo); Ce = Abe; @@ -6755,7 +6771,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Asu ^= Du; Bbu = ((((uint64_t)Asu) << 14) ^ (((uint64_t)Asu) >> (64 - 14))); Eba = Bba ^ (Bbe | Bbi); - Eba ^= KeccakF1600RoundConstants[22]; + Eba ^= kKeccakf[22]; Ca = Eba; Ebe = Bbe ^ ((~Bbi) | Bbo); Ce = Ebe; @@ -6861,7 +6877,7 @@ static size_t _PySHA3_KeccakF1600_FastLoop_Absorb(void *state, Esu ^= Du; Bbu = ((((uint64_t)Esu) << 14) ^ (((uint64_t)Esu) >> (64 - 14))); Aba = Bba ^ (Bbe | Bbi); - Aba ^= KeccakF1600RoundConstants[23]; + Aba ^= kKeccakf[23]; Abe = Bbe ^ ((~Bbi) | Bbo); Abi = Bbi ^ (Bbo & Bbu); Abo = Bbo ^ (Bbu | Bba); @@ -7968,3 +7984,8 @@ error: } while (0); return 0; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__sha3 = { + "_sha3", + PyInit__sha3, +}; diff --git a/third_party/python/Modules/_sqlite/module.c b/third_party/python/Modules/_sqlite/module.c index 8c3d88ca0..e09227ea2 100644 --- a/third_party/python/Modules/_sqlite/module.c +++ b/third_party/python/Modules/_sqlite/module.c @@ -491,3 +491,8 @@ error: } return module; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__sqlite3 = { + "_sqlite3", + PyInit__sqlite3, +}; diff --git a/third_party/python/Modules/_ssl.c b/third_party/python/Modules/_ssl.c deleted file mode 100644 index fdf186299..000000000 --- a/third_party/python/Modules/_ssl.c +++ /dev/null @@ -1,5713 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Python 3 │ -│ https://docs.python.org/3/license.html │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#define PY_SSIZE_T_CLEAN -#include "third_party/python/Include/yoink.h" -#include "third_party/python/Modules/socketmodule.h" -/* clang-format off */ - -PYTHON_PROVIDE("_ssl"); - -/* SSL socket module - - SSL support based on patches by Brian E Gallew and Laszlo Kovacs. - Re-worked a bit by Bill Janssen to add server-side support and - certificate decoding. Chris Stawarz contributed some non-blocking - patches. - - This module is imported by ssl.py. It should *not* be used - directly. - - XXX should partial writes be enabled, SSL_MODE_ENABLE_PARTIAL_WRITE? - - XXX integrate several "shutdown modes" as suggested in - http://bugs.python.org/issue8108#msg102867 ? -*/ - -#ifdef WITH_THREAD -#include "third_party/python/Include/pythread.h" -#define PySSL_BEGIN_ALLOW_THREADS_S(save) \ - do { if (_ssl_locks_count>0) { (save) = PyEval_SaveThread(); } } while (0) -#define PySSL_END_ALLOW_THREADS_S(save) \ - do { if (_ssl_locks_count>0) { PyEval_RestoreThread(save); } } while (0) -#define PySSL_BEGIN_ALLOW_THREADS { \ - PyThreadState *_save = NULL; \ - PySSL_BEGIN_ALLOW_THREADS_S(_save); -#define PySSL_BLOCK_THREADS PySSL_END_ALLOW_THREADS_S(_save); -#define PySSL_UNBLOCK_THREADS PySSL_BEGIN_ALLOW_THREADS_S(_save); -#define PySSL_END_ALLOW_THREADS PySSL_END_ALLOW_THREADS_S(_save); } -#else /* no WITH_THREAD */ -#define PySSL_BEGIN_ALLOW_THREADS_S(save) -#define PySSL_END_ALLOW_THREADS_S(save) -#define PySSL_BEGIN_ALLOW_THREADS -#define PySSL_BLOCK_THREADS -#define PySSL_UNBLOCK_THREADS -#define PySSL_END_ALLOW_THREADS -#endif - -/* Include symbols from _socket module */ - -static PySocketModule_APIObject PySocketModule; - -/* Don't warn about deprecated functions */ -#ifdef __GNUC__ -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif -#ifdef __clang__ -#pragma clang diagnostic ignored "-Wdeprecated-declarations" -#endif - -/* Include OpenSSL header files */ -#include "openssl/rsa.h" -#include "openssl/crypto.h" -#include "openssl/x509.h" -#include "openssl/x509v3.h" -#include "openssl/pem.h" -#include "openssl/ssl.h" -#include "openssl/err.h" -#include "openssl/rand.h" -#include "openssl/bio.h" -#include "openssl/dh.h" - -/* SSL error object */ -static PyObject *PySSLErrorObject; -static PyObject *PySSLZeroReturnErrorObject; -static PyObject *PySSLWantReadErrorObject; -static PyObject *PySSLWantWriteErrorObject; -static PyObject *PySSLSyscallErrorObject; -static PyObject *PySSLEOFErrorObject; - -/* Error mappings */ -static PyObject *err_codes_to_names; -static PyObject *err_names_to_codes; -static PyObject *lib_codes_to_names; - -struct py_ssl_error_code { - const char *mnemonic; - int library, reason; -}; -struct py_ssl_library_code { - const char *library; - int code; -}; - -/* Include generated data (error codes) */ -#include "third_party/python/Modules/_ssl_data.inc" - -#if (OPENSSL_VERSION_NUMBER >= 0x10100000L) && !defined(LIBRESSL_VERSION_NUMBER) -# define OPENSSL_VERSION_1_1 1 -# define PY_OPENSSL_1_1_API 1 -#endif - -/* LibreSSL 2.7.0 provides necessary OpenSSL 1.1.0 APIs */ -#if defined(LIBRESSL_VERSION_NUMBER) && LIBRESSL_VERSION_NUMBER >= 0x2070000fL -# define PY_OPENSSL_1_1_API 1 -#endif - -/* Openssl comes with TLSv1.1 and TLSv1.2 between 1.0.0h and 1.0.1 - http://www.openssl.org/news/changelog.html - */ -#if OPENSSL_VERSION_NUMBER >= 0x10001000L -# define HAVE_TLSv1_2 1 -#else -# define HAVE_TLSv1_2 0 -#endif - -/* SNI support (client- and server-side) appeared in OpenSSL 1.0.0 and 0.9.8f - * This includes the SSL_set_SSL_CTX() function. - */ -#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME -# define HAVE_SNI 1 -#else -# define HAVE_SNI 0 -#endif - -#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation -# define HAVE_ALPN 1 -#else -# define HAVE_ALPN 0 -#endif - -/* We cannot rely on OPENSSL_NO_NEXTPROTONEG because LibreSSL 2.6.1 dropped - * NPN support but did not set OPENSSL_NO_NEXTPROTONEG for compatibility - * reasons. The check for TLSEXT_TYPE_next_proto_neg works with - * OpenSSL 1.0.1+ and LibreSSL. - * OpenSSL 1.1.1-pre1 dropped NPN but still has TLSEXT_TYPE_next_proto_neg. - */ -#ifdef OPENSSL_NO_NEXTPROTONEG -# define HAVE_NPN 0 -#elif (OPENSSL_VERSION_NUMBER >= 0x10101000L) && !defined(LIBRESSL_VERSION_NUMBER) -# define HAVE_NPN 0 -#elif defined(TLSEXT_TYPE_next_proto_neg) -# define HAVE_NPN 1 -#else -# define HAVE_NPN 0 -#endif - -#ifndef INVALID_SOCKET /* MS defines this */ -#define INVALID_SOCKET (-1) -#endif - -/* OpenSSL 1.0.2 and LibreSSL needs extra code for locking */ -#if !defined(OPENSSL_VERSION_1_1) && defined(WITH_THREAD) -#define HAVE_OPENSSL_CRYPTO_LOCK -#endif - -#if defined(OPENSSL_VERSION_1_1) && !defined(OPENSSL_NO_SSL2) -#define OPENSSL_NO_SSL2 -#endif - -#ifndef PY_OPENSSL_1_1_API -/* OpenSSL 1.1 API shims for OpenSSL < 1.1.0 and LibreSSL < 2.7.0 */ - -#define TLS_method SSLv23_method -#define TLS_client_method SSLv23_client_method -#define TLS_server_method SSLv23_server_method - -static int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *ne) -{ - return ne->set; -} - -#ifndef OPENSSL_NO_COMP -/* LCOV_EXCL_START */ -static int COMP_get_type(const COMP_METHOD *meth) -{ - return meth->type; -} -/* LCOV_EXCL_STOP */ -#endif - -static pem_password_cb *SSL_CTX_get_default_passwd_cb(SSL_CTX *ctx) -{ - return ctx->default_passwd_callback; -} - -static void *SSL_CTX_get_default_passwd_cb_userdata(SSL_CTX *ctx) -{ - return ctx->default_passwd_callback_userdata; -} - -static int X509_OBJECT_get_type(X509_OBJECT *x) -{ - return x->type; -} - -static X509 *X509_OBJECT_get0_X509(X509_OBJECT *x) -{ - return x->data.x509; -} - -static int BIO_up_ref(BIO *b) -{ - CRYPTO_add(&b->references, 1, CRYPTO_LOCK_BIO); - return 1; -} - -static STACK_OF(X509_OBJECT) *X509_STORE_get0_objects(X509_STORE *store) { - return store->objs; -} - -static X509_VERIFY_PARAM *X509_STORE_get0_param(X509_STORE *store) -{ - return store->param; -} - -static int -SSL_SESSION_has_ticket(const SSL_SESSION *s) -{ - return (s->tlsext_ticklen > 0) ? 1 : 0; -} - -static unsigned long -SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *s) -{ - return s->tlsext_tick_lifetime_hint; -} - -#endif /* OpenSSL < 1.1.0 or LibreSSL < 2.7.0 */ - - -enum py_ssl_error { - /* these mirror ssl.h */ - PY_SSL_ERROR_NONE, - PY_SSL_ERROR_SSL, - PY_SSL_ERROR_WANT_READ, - PY_SSL_ERROR_WANT_WRITE, - PY_SSL_ERROR_WANT_X509_LOOKUP, - PY_SSL_ERROR_SYSCALL, /* look at error stack/return value/errno */ - PY_SSL_ERROR_ZERO_RETURN, - PY_SSL_ERROR_WANT_CONNECT, - /* start of non ssl.h errorcodes */ - PY_SSL_ERROR_EOF, /* special case of SSL_ERROR_SYSCALL */ - PY_SSL_ERROR_NO_SOCKET, /* socket has been GC'd */ - PY_SSL_ERROR_INVALID_ERROR_CODE -}; - -enum py_ssl_server_or_client { - PY_SSL_CLIENT, - PY_SSL_SERVER -}; - -enum py_ssl_cert_requirements { - PY_SSL_CERT_NONE, - PY_SSL_CERT_OPTIONAL, - PY_SSL_CERT_REQUIRED -}; - -enum py_ssl_version { - PY_SSL_VERSION_SSL2, - PY_SSL_VERSION_SSL3=1, - PY_SSL_VERSION_TLS, /* SSLv23 */ -#if HAVE_TLSv1_2 - PY_SSL_VERSION_TLS1, - PY_SSL_VERSION_TLS1_1, - PY_SSL_VERSION_TLS1_2, -#else - PY_SSL_VERSION_TLS1, -#endif - PY_SSL_VERSION_TLS_CLIENT=0x10, - PY_SSL_VERSION_TLS_SERVER, -}; - -#ifdef WITH_THREAD - -/* serves as a flag to see whether we've initialized the SSL thread support. */ -/* 0 means no, greater than 0 means yes */ - -static unsigned int _ssl_locks_count = 0; - -#endif /* def WITH_THREAD */ - -/* SSL socket object */ - -#define X509_NAME_MAXLEN 256 - -/* SSL_CTX_clear_options() and SSL_clear_options() were first added in - * OpenSSL 0.9.8m but do not appear in some 0.9.9-dev versions such the - * 0.9.9 from "May 2008" that NetBSD 5.0 uses. */ -#if OPENSSL_VERSION_NUMBER >= 0x009080dfL && OPENSSL_VERSION_NUMBER != 0x00909000L -# define HAVE_SSL_CTX_CLEAR_OPTIONS -#else -# undef HAVE_SSL_CTX_CLEAR_OPTIONS -#endif - -/* In case of 'tls-unique' it will be 12 bytes for TLS, 36 bytes for - * older SSL, but let's be safe */ -#define PySSL_CB_MAXLEN 128 - - -typedef struct { - PyObject_HEAD - SSL_CTX *ctx; -#if HAVE_NPN - unsigned char *npn_protocols; - int npn_protocols_len; -#endif -#if HAVE_ALPN - unsigned char *alpn_protocols; - int alpn_protocols_len; -#endif -#ifndef OPENSSL_NO_TLSEXT - PyObject *set_hostname; -#endif - int check_hostname; -#ifdef TLS1_3_VERSION - int post_handshake_auth; -#endif -} PySSLContext; - -typedef struct { - int ssl; /* last seen error from SSL */ - int c; /* last seen error from libc */ -#ifdef MS_WINDOWS - int ws; /* last seen error from winsock */ -#endif -} _PySSLError; - -typedef struct { - PyObject_HEAD - PyObject *Socket; /* weakref to socket on which we're layered */ - SSL *ssl; - PySSLContext *ctx; /* weakref to SSL context */ - char shutdown_seen_zero; - enum py_ssl_server_or_client socket_type; - PyObject *owner; /* Python level "owner" passed to servername callback */ - PyObject *server_hostname; - _PySSLError err; /* last seen error from various sources */ -} PySSLSocket; - -typedef struct { - PyObject_HEAD - BIO *bio; - int eof_written; -} PySSLMemoryBIO; - -typedef struct { - PyObject_HEAD - SSL_SESSION *session; - PySSLContext *ctx; -} PySSLSession; - -static PyTypeObject PySSLContext_Type; -static PyTypeObject PySSLSocket_Type; -static PyTypeObject PySSLMemoryBIO_Type; -static PyTypeObject PySSLSession_Type; - -static inline _PySSLError _PySSL_errno(int failed, const SSL *ssl, int retcode) -{ - _PySSLError err = { 0 }; - if (failed) { -#ifdef MS_WINDOWS - err.ws = WSAGetLastError(); -#endif - err.c = errno; - err.ssl = SSL_get_error(ssl, retcode); - } - return err; -} - -/*[clinic input] -module _ssl -class _ssl._SSLContext "PySSLContext *" "&PySSLContext_Type" -class _ssl._SSLSocket "PySSLSocket *" "&PySSLSocket_Type" -class _ssl.MemoryBIO "PySSLMemoryBIO *" "&PySSLMemoryBIO_Type" -class _ssl.SSLSession "PySSLSession *" "&PySSLSession_Type" -[clinic start generated code]*/ -/*[clinic end generated code: output=da39a3ee5e6b4b0d input=bdc67fafeeaa8109]*/ - -#include "third_party/python/Modules/clinic/_ssl.inc" - -static int PySSL_select(PySocketSockObject *s, int writing, _PyTime_t timeout); - - -#define PySSLContext_Check(v) (Py_TYPE(v) == &PySSLContext_Type) -#define PySSLSocket_Check(v) (Py_TYPE(v) == &PySSLSocket_Type) -#define PySSLMemoryBIO_Check(v) (Py_TYPE(v) == &PySSLMemoryBIO_Type) -#define PySSLSession_Check(v) (Py_TYPE(v) == &PySSLSession_Type) - -typedef enum { - SOCKET_IS_NONBLOCKING, - SOCKET_IS_BLOCKING, - SOCKET_HAS_TIMED_OUT, - SOCKET_HAS_BEEN_CLOSED, - SOCKET_TOO_LARGE_FOR_SELECT, - SOCKET_OPERATION_OK -} timeout_state; - -/* Wrap error strings with filename and line # */ -#define ERRSTR1(x,y,z) (x ":" y ": " z) -#define ERRSTR(x) ERRSTR1("_ssl.c", Py_STRINGIFY(__LINE__), x) - -/* Get the socket from a PySSLSocket, if it has one */ -#define GET_SOCKET(obj) ((obj)->Socket ? \ - (PySocketSockObject *) PyWeakref_GetObject((obj)->Socket) : NULL) - -/* If sock is NULL, use a timeout of 0 second */ -#define GET_SOCKET_TIMEOUT(sock) \ - ((sock != NULL) ? (sock)->sock_timeout : 0) - -/* - * SSL errors. - */ - -PyDoc_STRVAR(SSLError_doc, -"An error occurred in the SSL implementation."); - -PyDoc_STRVAR(SSLZeroReturnError_doc, -"SSL/TLS session closed cleanly."); - -PyDoc_STRVAR(SSLWantReadError_doc, -"Non-blocking SSL socket needs to read more data\n" -"before the requested operation can be completed."); - -PyDoc_STRVAR(SSLWantWriteError_doc, -"Non-blocking SSL socket needs to write more data\n" -"before the requested operation can be completed."); - -PyDoc_STRVAR(SSLSyscallError_doc, -"System error when attempting SSL operation."); - -PyDoc_STRVAR(SSLEOFError_doc, -"SSL/TLS connection terminated abruptly."); - -static PyObject * -SSLError_str(PyOSErrorObject *self) -{ - if (self->strerror != NULL && PyUnicode_Check(self->strerror)) { - Py_INCREF(self->strerror); - return self->strerror; - } - else - return PyObject_Str(self->args); -} - -static PyType_Slot sslerror_type_slots[] = { - {Py_tp_base, NULL}, /* Filled out in module init as it's not a constant */ - {Py_tp_doc, SSLError_doc}, - {Py_tp_str, SSLError_str}, - {0, 0}, -}; - -static PyType_Spec sslerror_type_spec = { - "ssl.SSLError", - sizeof(PyOSErrorObject), - 0, - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - sslerror_type_slots -}; - -static void -fill_and_set_sslerror(PyObject *type, int ssl_errno, const char *errstr, - int lineno, unsigned long errcode) -{ - PyObject *err_value = NULL, *reason_obj = NULL, *lib_obj = NULL; - PyObject *init_value, *msg, *key; - _Py_IDENTIFIER(reason); - _Py_IDENTIFIER(library); - - if (errcode != 0) { - int lib, reason; - - lib = ERR_GET_LIB(errcode); - reason = ERR_GET_REASON(errcode); - key = Py_BuildValue("ii", lib, reason); - if (key == NULL) - goto fail; - reason_obj = PyDict_GetItem(err_codes_to_names, key); - Py_DECREF(key); - if (reason_obj == NULL) { - /* XXX if reason < 100, it might reflect a library number (!!) */ - PyErr_Clear(); - } - key = PyLong_FromLong(lib); - if (key == NULL) - goto fail; - lib_obj = PyDict_GetItem(lib_codes_to_names, key); - Py_DECREF(key); - if (lib_obj == NULL) { - PyErr_Clear(); - } - if (errstr == NULL) - errstr = ERR_reason_error_string(errcode); - } - if (errstr == NULL) - errstr = "unknown error"; - - if (reason_obj && lib_obj) - msg = PyUnicode_FromFormat("[%S: %S] %s (_ssl.c:%d)", - lib_obj, reason_obj, errstr, lineno); - else if (lib_obj) - msg = PyUnicode_FromFormat("[%S] %s (_ssl.c:%d)", - lib_obj, errstr, lineno); - else - msg = PyUnicode_FromFormat("%s (_ssl.c:%d)", errstr, lineno); - if (msg == NULL) - goto fail; - - init_value = Py_BuildValue("iN", ssl_errno, msg); - if (init_value == NULL) - goto fail; - - err_value = PyObject_CallObject(type, init_value); - Py_DECREF(init_value); - if (err_value == NULL) - goto fail; - - if (reason_obj == NULL) - reason_obj = Py_None; - if (_PyObject_SetAttrId(err_value, &PyId_reason, reason_obj)) - goto fail; - if (lib_obj == NULL) - lib_obj = Py_None; - if (_PyObject_SetAttrId(err_value, &PyId_library, lib_obj)) - goto fail; - PyErr_SetObject(type, err_value); -fail: - Py_XDECREF(err_value); -} - -static PyObject * -PySSL_SetError(PySSLSocket *obj, int ret, const char *filename, int lineno) -{ - PyObject *type = PySSLErrorObject; - char *errstr = NULL; - _PySSLError err; - enum py_ssl_error p = PY_SSL_ERROR_NONE; - unsigned long e = 0; - - assert(ret <= 0); - e = ERR_peek_last_error(); - - if (obj->ssl != NULL) { - err = obj->err; - - switch (err.ssl) { - case SSL_ERROR_ZERO_RETURN: - errstr = "TLS/SSL connection has been closed (EOF)"; - type = PySSLZeroReturnErrorObject; - p = PY_SSL_ERROR_ZERO_RETURN; - break; - case SSL_ERROR_WANT_READ: - errstr = "The operation did not complete (read)"; - type = PySSLWantReadErrorObject; - p = PY_SSL_ERROR_WANT_READ; - break; - case SSL_ERROR_WANT_WRITE: - p = PY_SSL_ERROR_WANT_WRITE; - type = PySSLWantWriteErrorObject; - errstr = "The operation did not complete (write)"; - break; - case SSL_ERROR_WANT_X509_LOOKUP: - p = PY_SSL_ERROR_WANT_X509_LOOKUP; - errstr = "The operation did not complete (X509 lookup)"; - break; - case SSL_ERROR_WANT_CONNECT: - p = PY_SSL_ERROR_WANT_CONNECT; - errstr = "The operation did not complete (connect)"; - break; - case SSL_ERROR_SYSCALL: - { - if (e == 0) { - PySocketSockObject *s = GET_SOCKET(obj); - if (ret == 0 || (((PyObject *)s) == Py_None)) { - p = PY_SSL_ERROR_EOF; - type = PySSLEOFErrorObject; - errstr = "EOF occurred in violation of protocol"; - } else if (s && ret == -1) { - /* underlying BIO reported an I/O error */ - ERR_clear_error(); -#ifdef MS_WINDOWS - if (err.ws) { - return PyErr_SetFromWindowsErr(err.ws); - } -#endif - if (err.c) { - errno = err.c; - return PyErr_SetFromErrno(PyExc_OSError); - } - Py_INCREF(s); - s->errorhandler(); - Py_DECREF(s); - return NULL; - } else { /* possible? */ - p = PY_SSL_ERROR_SYSCALL; - type = PySSLSyscallErrorObject; - errstr = "Some I/O error occurred"; - } - } else { - p = PY_SSL_ERROR_SYSCALL; - } - break; - } - case SSL_ERROR_SSL: - { - p = PY_SSL_ERROR_SSL; - if (e == 0) - /* possible? */ - errstr = "A failure in the SSL library occurred"; - break; - } - default: - p = PY_SSL_ERROR_INVALID_ERROR_CODE; - errstr = "Invalid error code"; - } - } - fill_and_set_sslerror(type, p, errstr, lineno, e); - ERR_clear_error(); - return NULL; -} - -static PyObject * -_setSSLError (const char *errstr, int errcode, const char *filename, int lineno) { - - if (errstr == NULL) - errcode = ERR_peek_last_error(); - else - errcode = 0; - fill_and_set_sslerror(PySSLErrorObject, errcode, errstr, lineno, errcode); - ERR_clear_error(); - return NULL; -} - -/* - * SSL objects - */ - -static PySSLSocket * -newPySSLSocket(PySSLContext *sslctx, PySocketSockObject *sock, - enum py_ssl_server_or_client socket_type, - char *server_hostname, - PySSLMemoryBIO *inbio, PySSLMemoryBIO *outbio) -{ - PySSLSocket *self; - SSL_CTX *ctx = sslctx->ctx; - long mode; - _PySSLError err = { 0 }; - - self = PyObject_New(PySSLSocket, &PySSLSocket_Type); - if (self == NULL) - return NULL; - - self->ssl = NULL; - self->Socket = NULL; - self->ctx = sslctx; - Py_INCREF(sslctx); - self->shutdown_seen_zero = 0; - self->owner = NULL; - self->server_hostname = NULL; - if (server_hostname != NULL) { - PyObject *hostname = PyUnicode_Decode(server_hostname, strlen(server_hostname), - "idna", "strict"); - if (hostname == NULL) { - Py_DECREF(self); - return NULL; - } - self->server_hostname = hostname; - } - self->err = err; - - /* Make sure the SSL error state is initialized */ - (void) ERR_get_state(); - ERR_clear_error(); - - PySSL_BEGIN_ALLOW_THREADS - self->ssl = SSL_new(ctx); - PySSL_END_ALLOW_THREADS - if (self->ssl == NULL) { - Py_DECREF(self); - _setSSLError(NULL, 0, __FILE__, __LINE__); - return NULL; - } - SSL_set_app_data(self->ssl, self); - if (sock) { - SSL_set_fd(self->ssl, Py_SAFE_DOWNCAST(sock->sock_fd, SOCKET_T, int)); - } else { - /* BIOs are reference counted and SSL_set_bio borrows our reference. - * To prevent a double free in memory_bio_dealloc() we need to take an - * extra reference here. */ - BIO_up_ref(inbio->bio); - BIO_up_ref(outbio->bio); - SSL_set_bio(self->ssl, inbio->bio, outbio->bio); - } - mode = SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER; -#ifdef SSL_MODE_AUTO_RETRY - mode |= SSL_MODE_AUTO_RETRY; -#endif - SSL_set_mode(self->ssl, mode); - -#if HAVE_SNI - if (server_hostname != NULL) { -/* Don't send SNI for IP addresses. We cannot simply use inet_aton() and - * inet_pton() here. inet_aton() may be linked weakly and inet_pton() isn't - * available on all platforms. Use OpenSSL's IP address parser. It's - * available since 1.0.2 and LibreSSL since at least 2.3.0. */ - int send_sni = 1; -#if OPENSSL_VERSION_NUMBER >= 0x10200000L - ASN1_OCTET_STRING *ip = a2i_IPADDRESS(server_hostname); - if (ip == NULL) { - send_sni = 1; - ERR_clear_error(); - } else { - send_sni = 0; - ASN1_OCTET_STRING_free(ip); - } -#elif defined(HAVE_INET_PTON) -#ifdef ENABLE_IPV6 - char packed[Py_MAX(sizeof(struct in_addr), sizeof(struct in6_addr))]; -#else - char packed[sizeof(struct in_addr)]; -#endif /* ENABLE_IPV6 */ - if (inet_pton(AF_INET, server_hostname, packed)) { - send_sni = 0; -#ifdef ENABLE_IPV6 - } else if(inet_pton(AF_INET6, server_hostname, packed)) { - send_sni = 0; -#endif /* ENABLE_IPV6 */ - } else { - send_sni = 1; - } -#endif /* HAVE_INET_PTON */ - if (send_sni) { - SSL_set_tlsext_host_name(self->ssl, server_hostname); - } - } -#endif - - /* If the socket is in non-blocking mode or timeout mode, set the BIO - * to non-blocking mode (blocking is the default) - */ - if (sock && sock->sock_timeout >= 0) { - BIO_set_nbio(SSL_get_rbio(self->ssl), 1); - BIO_set_nbio(SSL_get_wbio(self->ssl), 1); - } - - PySSL_BEGIN_ALLOW_THREADS - if (socket_type == PY_SSL_CLIENT) - SSL_set_connect_state(self->ssl); - else - SSL_set_accept_state(self->ssl); - PySSL_END_ALLOW_THREADS - - self->socket_type = socket_type; - if (sock != NULL) { - self->Socket = PyWeakref_NewRef((PyObject *) sock, NULL); - if (self->Socket == NULL) { - Py_DECREF(self); - return NULL; - } - } - return self; -} - -/* SSL object methods */ - -/*[clinic input] -_ssl._SSLSocket.do_handshake -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLSocket_do_handshake_impl(PySSLSocket *self) -/*[clinic end generated code: output=6c0898a8936548f6 input=d2d737de3df018c8]*/ -{ - int ret; - _PySSLError err; - int sockstate, nonblocking; - PySocketSockObject *sock = GET_SOCKET(self); - _PyTime_t timeout, deadline = 0; - int has_timeout; - - if (sock) { - if (((PyObject*)sock) == Py_None) { - _setSSLError("Underlying socket connection gone", - PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__); - return NULL; - } - Py_INCREF(sock); - - /* just in case the blocking state of the socket has been changed */ - nonblocking = (sock->sock_timeout >= 0); - BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking); - BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking); - } - - timeout = GET_SOCKET_TIMEOUT(sock); - has_timeout = (timeout > 0); - if (has_timeout) - deadline = _PyTime_GetMonotonicClock() + timeout; - - /* Actually negotiate SSL connection */ - /* XXX If SSL_do_handshake() returns 0, it's also a failure. */ - do { - PySSL_BEGIN_ALLOW_THREADS - ret = SSL_do_handshake(self->ssl); - err = _PySSL_errno(ret < 1, self->ssl, ret); - PySSL_END_ALLOW_THREADS - self->err = err; - - if (PyErr_CheckSignals()) - goto error; - - if (has_timeout) - timeout = deadline - _PyTime_GetMonotonicClock(); - - if (err.ssl == SSL_ERROR_WANT_READ) { - sockstate = PySSL_select(sock, 0, timeout); - } else if (err.ssl == SSL_ERROR_WANT_WRITE) { - sockstate = PySSL_select(sock, 1, timeout); - } else { - sockstate = SOCKET_OPERATION_OK; - } - - if (sockstate == SOCKET_HAS_TIMED_OUT) { - PyErr_SetString(PySocketModule.timeout_error, - ERRSTR("The handshake operation timed out")); - goto error; - } else if (sockstate == SOCKET_HAS_BEEN_CLOSED) { - PyErr_SetString(PySSLErrorObject, - ERRSTR("Underlying socket has been closed.")); - goto error; - } else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) { - PyErr_SetString(PySSLErrorObject, - ERRSTR("Underlying socket too large for select().")); - goto error; - } else if (sockstate == SOCKET_IS_NONBLOCKING) { - break; - } - } while (err.ssl == SSL_ERROR_WANT_READ || - err.ssl == SSL_ERROR_WANT_WRITE); - Py_XDECREF(sock); - if (ret < 1) - return PySSL_SetError(self, ret, __FILE__, __LINE__); - - Py_RETURN_NONE; - -error: - Py_XDECREF(sock); - return NULL; -} - -static PyObject * -_asn1obj2py(const ASN1_OBJECT *name, int no_name) -{ - char buf[X509_NAME_MAXLEN]; - char *namebuf = buf; - int buflen; - PyObject *name_obj = NULL; - - buflen = OBJ_obj2txt(namebuf, X509_NAME_MAXLEN, name, no_name); - if (buflen < 0) { - _setSSLError(NULL, 0, __FILE__, __LINE__); - return NULL; - } - /* initial buffer is too small for oid + terminating null byte */ - if (buflen > X509_NAME_MAXLEN - 1) { - /* make OBJ_obj2txt() calculate the required buflen */ - buflen = OBJ_obj2txt(NULL, 0, name, no_name); - /* allocate len + 1 for terminating NULL byte */ - namebuf = PyMem_Malloc(buflen + 1); - if (namebuf == NULL) { - PyErr_NoMemory(); - return NULL; - } - buflen = OBJ_obj2txt(namebuf, buflen + 1, name, no_name); - if (buflen < 0) { - _setSSLError(NULL, 0, __FILE__, __LINE__); - goto done; - } - } - if (!buflen && no_name) { - Py_INCREF(Py_None); - name_obj = Py_None; - } - else { - name_obj = PyUnicode_FromStringAndSize(namebuf, buflen); - } - - done: - if (buf != namebuf) { - PyMem_Free(namebuf); - } - return name_obj; -} - -static PyObject * -_create_tuple_for_attribute(ASN1_OBJECT *name, ASN1_STRING *value) -{ - Py_ssize_t buflen; - unsigned char *valuebuf = NULL; - PyObject *attr; - - buflen = ASN1_STRING_to_UTF8(&valuebuf, value); - if (buflen < 0) { - _setSSLError(NULL, 0, __FILE__, __LINE__); - return NULL; - } - attr = Py_BuildValue("Ns#", _asn1obj2py(name, 0), valuebuf, buflen); - OPENSSL_free(valuebuf); - return attr; -} - -static PyObject * -_create_tuple_for_X509_NAME (X509_NAME *xname) -{ - PyObject *dn = NULL; /* tuple which represents the "distinguished name" */ - PyObject *rdn = NULL; /* tuple to hold a "relative distinguished name" */ - PyObject *rdnt; - PyObject *attr = NULL; /* tuple to hold an attribute */ - int entry_count = X509_NAME_entry_count(xname); - X509_NAME_ENTRY *entry; - ASN1_OBJECT *name; - ASN1_STRING *value; - int index_counter; - int rdn_level = -1; - int retcode; - - dn = PyList_New(0); - if (dn == NULL) - return NULL; - /* now create another tuple to hold the top-level RDN */ - rdn = PyList_New(0); - if (rdn == NULL) - goto fail0; - - for (index_counter = 0; - index_counter < entry_count; - index_counter++) - { - entry = X509_NAME_get_entry(xname, index_counter); - - /* check to see if we've gotten to a new RDN */ - if (rdn_level >= 0) { - if (rdn_level != X509_NAME_ENTRY_set(entry)) { - /* yes, new RDN */ - /* add old RDN to DN */ - rdnt = PyList_AsTuple(rdn); - Py_DECREF(rdn); - if (rdnt == NULL) - goto fail0; - retcode = PyList_Append(dn, rdnt); - Py_DECREF(rdnt); - if (retcode < 0) - goto fail0; - /* create new RDN */ - rdn = PyList_New(0); - if (rdn == NULL) - goto fail0; - } - } - rdn_level = X509_NAME_ENTRY_set(entry); - - /* now add this attribute to the current RDN */ - name = X509_NAME_ENTRY_get_object(entry); - value = X509_NAME_ENTRY_get_data(entry); - attr = _create_tuple_for_attribute(name, value); - /* - fprintf(stderr, "RDN level %d, attribute %s: %s\n", - entry->set, - PyBytes_AS_STRING(PyTuple_GET_ITEM(attr, 0)), - PyBytes_AS_STRING(PyTuple_GET_ITEM(attr, 1))); - */ - if (attr == NULL) - goto fail1; - retcode = PyList_Append(rdn, attr); - Py_DECREF(attr); - if (retcode < 0) - goto fail1; - } - /* now, there's typically a dangling RDN */ - if (rdn != NULL) { - if (PyList_GET_SIZE(rdn) > 0) { - rdnt = PyList_AsTuple(rdn); - Py_DECREF(rdn); - if (rdnt == NULL) - goto fail0; - retcode = PyList_Append(dn, rdnt); - Py_DECREF(rdnt); - if (retcode < 0) - goto fail0; - } - else { - Py_DECREF(rdn); - } - } - - /* convert list to tuple */ - rdnt = PyList_AsTuple(dn); - Py_DECREF(dn); - if (rdnt == NULL) - return NULL; - return rdnt; - - fail1: - Py_XDECREF(rdn); - - fail0: - Py_XDECREF(dn); - return NULL; -} - -static PyObject * -_get_peer_alt_names (X509 *certificate) { - - /* this code follows the procedure outlined in - OpenSSL's crypto/x509v3/v3_prn.c:X509v3_EXT_print() - function to extract the STACK_OF(GENERAL_NAME), - then iterates through the stack to add the - names. */ - - int i, j; - PyObject *peer_alt_names = Py_None; - PyObject *v = NULL, *t; - X509_EXTENSION *ext = NULL; - GENERAL_NAMES *names = NULL; - GENERAL_NAME *name; - const X509V3_EXT_METHOD *method; - BIO *biobuf = NULL; - char buf[2048]; - char *vptr; - int len; - const unsigned char *p; - - if (certificate == NULL) - return peer_alt_names; - - /* get a memory buffer */ - biobuf = BIO_new(BIO_s_mem()); - if (biobuf == NULL) { - PyErr_SetString(PySSLErrorObject, "failed to allocate BIO"); - return NULL; - } - - i = -1; - while ((i = X509_get_ext_by_NID( - certificate, NID_subject_alt_name, i)) >= 0) { - - if (peer_alt_names == Py_None) { - peer_alt_names = PyList_New(0); - if (peer_alt_names == NULL) - goto fail; - } - - /* now decode the altName */ - ext = X509_get_ext(certificate, i); - if(!(method = X509V3_EXT_get(ext))) { - PyErr_SetString - (PySSLErrorObject, - ERRSTR("No method for internalizing subjectAltName!")); - goto fail; - } - - p = X509_EXTENSION_get_data(ext)->data; - if (method->it) - names = (GENERAL_NAMES*) - (ASN1_item_d2i(NULL, - &p, - X509_EXTENSION_get_data(ext)->length, - ASN1_ITEM_ptr(method->it))); - else - names = (GENERAL_NAMES*) - (method->d2i(NULL, - &p, - X509_EXTENSION_get_data(ext)->length)); - - for(j = 0; j < sk_GENERAL_NAME_num(names); j++) { - /* get a rendering of each name in the set of names */ - int gntype; - ASN1_STRING *as = NULL; - - name = sk_GENERAL_NAME_value(names, j); - gntype = name->type; - switch (gntype) { - case GEN_DIRNAME: - /* we special-case DirName as a tuple of - tuples of attributes */ - - t = PyTuple_New(2); - if (t == NULL) { - goto fail; - } - - v = PyUnicode_FromString("DirName"); - if (v == NULL) { - Py_DECREF(t); - goto fail; - } - PyTuple_SET_ITEM(t, 0, v); - - v = _create_tuple_for_X509_NAME (name->d.dirn); - if (v == NULL) { - Py_DECREF(t); - goto fail; - } - PyTuple_SET_ITEM(t, 1, v); - break; - - case GEN_EMAIL: - case GEN_DNS: - case GEN_URI: - /* GENERAL_NAME_print() doesn't handle NULL bytes in ASN1_string - correctly, CVE-2013-4238 */ - t = PyTuple_New(2); - if (t == NULL) - goto fail; - switch (gntype) { - case GEN_EMAIL: - v = PyUnicode_FromString("email"); - as = name->d.rfc822Name; - break; - case GEN_DNS: - v = PyUnicode_FromString("DNS"); - as = name->d.dNSName; - break; - case GEN_URI: - v = PyUnicode_FromString("URI"); - as = name->d.uniformResourceIdentifier; - break; - } - if (v == NULL) { - Py_DECREF(t); - goto fail; - } - PyTuple_SET_ITEM(t, 0, v); - v = PyUnicode_FromStringAndSize((char *)ASN1_STRING_data(as), - ASN1_STRING_length(as)); - if (v == NULL) { - Py_DECREF(t); - goto fail; - } - PyTuple_SET_ITEM(t, 1, v); - break; - - case GEN_RID: - t = PyTuple_New(2); - if (t == NULL) - goto fail; - - v = PyUnicode_FromString("Registered ID"); - if (v == NULL) { - Py_DECREF(t); - goto fail; - } - PyTuple_SET_ITEM(t, 0, v); - - len = i2t_ASN1_OBJECT(buf, sizeof(buf)-1, name->d.rid); - if (len < 0) { - Py_DECREF(t); - _setSSLError(NULL, 0, __FILE__, __LINE__); - goto fail; - } else if (len >= (int)sizeof(buf)) { - v = PyUnicode_FromString(""); - } else { - v = PyUnicode_FromStringAndSize(buf, len); - } - if (v == NULL) { - Py_DECREF(t); - goto fail; - } - PyTuple_SET_ITEM(t, 1, v); - break; - - default: - /* for everything else, we use the OpenSSL print form */ - switch (gntype) { - /* check for new general name type */ - case GEN_OTHERNAME: - case GEN_X400: - case GEN_EDIPARTY: - case GEN_IPADD: - case GEN_RID: - break; - default: - if (PyErr_WarnFormat(PyExc_RuntimeWarning, 1, - "Unknown general name type %d", - gntype) == -1) { - goto fail; - } - break; - } - (void) BIO_reset(biobuf); - GENERAL_NAME_print(biobuf, name); - len = BIO_gets(biobuf, buf, sizeof(buf)-1); - if (len < 0) { - _setSSLError(NULL, 0, __FILE__, __LINE__); - goto fail; - } - vptr = strchr(buf, ':'); - if (vptr == NULL) { - PyErr_Format(PyExc_ValueError, - "Invalid value %.200s", - buf); - goto fail; - } - t = PyTuple_New(2); - if (t == NULL) - goto fail; - v = PyUnicode_FromStringAndSize(buf, (vptr - buf)); - if (v == NULL) { - Py_DECREF(t); - goto fail; - } - PyTuple_SET_ITEM(t, 0, v); - v = PyUnicode_FromStringAndSize((vptr + 1), - (len - (vptr - buf + 1))); - if (v == NULL) { - Py_DECREF(t); - goto fail; - } - PyTuple_SET_ITEM(t, 1, v); - break; - } - - /* and add that rendering to the list */ - - if (PyList_Append(peer_alt_names, t) < 0) { - Py_DECREF(t); - goto fail; - } - Py_DECREF(t); - } - sk_GENERAL_NAME_pop_free(names, GENERAL_NAME_free); - } - BIO_free(biobuf); - if (peer_alt_names != Py_None) { - v = PyList_AsTuple(peer_alt_names); - Py_DECREF(peer_alt_names); - return v; - } else { - return peer_alt_names; - } - - - fail: - if (biobuf != NULL) - BIO_free(biobuf); - - if (peer_alt_names != Py_None) { - Py_XDECREF(peer_alt_names); - } - - return NULL; -} - -static PyObject * -_get_aia_uri(X509 *certificate, int nid) { - PyObject *lst = NULL, *ostr = NULL; - int i, result; - AUTHORITY_INFO_ACCESS *info; - - info = X509_get_ext_d2i(certificate, NID_info_access, NULL, NULL); - if (info == NULL) - return Py_None; - if (sk_ACCESS_DESCRIPTION_num(info) == 0) { - AUTHORITY_INFO_ACCESS_free(info); - return Py_None; - } - - if ((lst = PyList_New(0)) == NULL) { - goto fail; - } - - for (i = 0; i < sk_ACCESS_DESCRIPTION_num(info); i++) { - ACCESS_DESCRIPTION *ad = sk_ACCESS_DESCRIPTION_value(info, i); - ASN1_IA5STRING *uri; - - if ((OBJ_obj2nid(ad->method) != nid) || - (ad->location->type != GEN_URI)) { - continue; - } - uri = ad->location->d.uniformResourceIdentifier; - ostr = PyUnicode_FromStringAndSize((char *)uri->data, - uri->length); - if (ostr == NULL) { - goto fail; - } - result = PyList_Append(lst, ostr); - Py_DECREF(ostr); - if (result < 0) { - goto fail; - } - } - AUTHORITY_INFO_ACCESS_free(info); - - /* convert to tuple or None */ - if (PyList_Size(lst) == 0) { - Py_DECREF(lst); - return Py_None; - } else { - PyObject *tup; - tup = PyList_AsTuple(lst); - Py_DECREF(lst); - return tup; - } - - fail: - AUTHORITY_INFO_ACCESS_free(info); - Py_XDECREF(lst); - return NULL; -} - -static PyObject * -_get_crl_dp(X509 *certificate) { - STACK_OF(DIST_POINT) *dps; - int i, j; - PyObject *lst, *res = NULL; - - dps = X509_get_ext_d2i(certificate, NID_crl_distribution_points, NULL, NULL); - - if (dps == NULL) - return Py_None; - - lst = PyList_New(0); - if (lst == NULL) - goto done; - - for (i=0; i < sk_DIST_POINT_num(dps); i++) { - DIST_POINT *dp; - STACK_OF(GENERAL_NAME) *gns; - - dp = sk_DIST_POINT_value(dps, i); - if (dp->distpoint == NULL) { - /* Ignore empty DP value, CVE-2019-5010 */ - continue; - } - gns = dp->distpoint->name.fullname; - - for (j=0; j < sk_GENERAL_NAME_num(gns); j++) { - GENERAL_NAME *gn; - ASN1_IA5STRING *uri; - PyObject *ouri; - int err; - - gn = sk_GENERAL_NAME_value(gns, j); - if (gn->type != GEN_URI) { - continue; - } - uri = gn->d.uniformResourceIdentifier; - ouri = PyUnicode_FromStringAndSize((char *)uri->data, - uri->length); - if (ouri == NULL) - goto done; - - err = PyList_Append(lst, ouri); - Py_DECREF(ouri); - if (err < 0) - goto done; - } - } - - /* Convert to tuple. */ - res = (PyList_GET_SIZE(lst) > 0) ? PyList_AsTuple(lst) : Py_None; - - done: - Py_XDECREF(lst); - CRL_DIST_POINTS_free(dps); - return res; -} - -static PyObject * -_decode_certificate(X509 *certificate) { - - PyObject *retval = NULL; - BIO *biobuf = NULL; - PyObject *peer; - PyObject *peer_alt_names = NULL; - PyObject *issuer; - PyObject *version; - PyObject *sn_obj; - PyObject *obj; - ASN1_INTEGER *serialNumber; - char buf[2048]; - int len, result; - ASN1_TIME *notBefore, *notAfter; - PyObject *pnotBefore, *pnotAfter; - - retval = PyDict_New(); - if (retval == NULL) - return NULL; - - peer = _create_tuple_for_X509_NAME( - X509_get_subject_name(certificate)); - if (peer == NULL) - goto fail0; - if (PyDict_SetItemString(retval, (const char *) "subject", peer) < 0) { - Py_DECREF(peer); - goto fail0; - } - Py_DECREF(peer); - - issuer = _create_tuple_for_X509_NAME( - X509_get_issuer_name(certificate)); - if (issuer == NULL) - goto fail0; - if (PyDict_SetItemString(retval, (const char *)"issuer", issuer) < 0) { - Py_DECREF(issuer); - goto fail0; - } - Py_DECREF(issuer); - - version = PyLong_FromLong(X509_get_version(certificate) + 1); - if (version == NULL) - goto fail0; - if (PyDict_SetItemString(retval, "version", version) < 0) { - Py_DECREF(version); - goto fail0; - } - Py_DECREF(version); - - /* get a memory buffer */ - biobuf = BIO_new(BIO_s_mem()); - if (biobuf == NULL) { - PyErr_SetString(PySSLErrorObject, "failed to allocate BIO"); - goto fail0; - } - - (void) BIO_reset(biobuf); - serialNumber = X509_get_serialNumber(certificate); - /* should not exceed 20 octets, 160 bits, so buf is big enough */ - i2a_ASN1_INTEGER(biobuf, serialNumber); - len = BIO_gets(biobuf, buf, sizeof(buf)-1); - if (len < 0) { - _setSSLError(NULL, 0, __FILE__, __LINE__); - goto fail1; - } - sn_obj = PyUnicode_FromStringAndSize(buf, len); - if (sn_obj == NULL) - goto fail1; - if (PyDict_SetItemString(retval, "serialNumber", sn_obj) < 0) { - Py_DECREF(sn_obj); - goto fail1; - } - Py_DECREF(sn_obj); - - (void) BIO_reset(biobuf); - notBefore = X509_get_notBefore(certificate); - ASN1_TIME_print(biobuf, notBefore); - len = BIO_gets(biobuf, buf, sizeof(buf)-1); - if (len < 0) { - _setSSLError(NULL, 0, __FILE__, __LINE__); - goto fail1; - } - pnotBefore = PyUnicode_FromStringAndSize(buf, len); - if (pnotBefore == NULL) - goto fail1; - if (PyDict_SetItemString(retval, "notBefore", pnotBefore) < 0) { - Py_DECREF(pnotBefore); - goto fail1; - } - Py_DECREF(pnotBefore); - - (void) BIO_reset(biobuf); - notAfter = X509_get_notAfter(certificate); - ASN1_TIME_print(biobuf, notAfter); - len = BIO_gets(biobuf, buf, sizeof(buf)-1); - if (len < 0) { - _setSSLError(NULL, 0, __FILE__, __LINE__); - goto fail1; - } - pnotAfter = PyUnicode_FromStringAndSize(buf, len); - if (pnotAfter == NULL) - goto fail1; - if (PyDict_SetItemString(retval, "notAfter", pnotAfter) < 0) { - Py_DECREF(pnotAfter); - goto fail1; - } - Py_DECREF(pnotAfter); - - /* Now look for subjectAltName */ - - peer_alt_names = _get_peer_alt_names(certificate); - if (peer_alt_names == NULL) - goto fail1; - else if (peer_alt_names != Py_None) { - if (PyDict_SetItemString(retval, "subjectAltName", - peer_alt_names) < 0) { - Py_DECREF(peer_alt_names); - goto fail1; - } - Py_DECREF(peer_alt_names); - } - - /* Authority Information Access: OCSP URIs */ - obj = _get_aia_uri(certificate, NID_ad_OCSP); - if (obj == NULL) { - goto fail1; - } else if (obj != Py_None) { - result = PyDict_SetItemString(retval, "OCSP", obj); - Py_DECREF(obj); - if (result < 0) { - goto fail1; - } - } - - obj = _get_aia_uri(certificate, NID_ad_ca_issuers); - if (obj == NULL) { - goto fail1; - } else if (obj != Py_None) { - result = PyDict_SetItemString(retval, "caIssuers", obj); - Py_DECREF(obj); - if (result < 0) { - goto fail1; - } - } - - /* CDP (CRL distribution points) */ - obj = _get_crl_dp(certificate); - if (obj == NULL) { - goto fail1; - } else if (obj != Py_None) { - result = PyDict_SetItemString(retval, "crlDistributionPoints", obj); - Py_DECREF(obj); - if (result < 0) { - goto fail1; - } - } - - BIO_free(biobuf); - return retval; - - fail1: - if (biobuf != NULL) - BIO_free(biobuf); - fail0: - Py_XDECREF(retval); - return NULL; -} - -static PyObject * -_certificate_to_der(X509 *certificate) -{ - unsigned char *bytes_buf = NULL; - int len; - PyObject *retval; - - bytes_buf = NULL; - len = i2d_X509(certificate, &bytes_buf); - if (len < 0) { - _setSSLError(NULL, 0, __FILE__, __LINE__); - return NULL; - } - /* this is actually an immutable bytes sequence */ - retval = PyBytes_FromStringAndSize((const char *) bytes_buf, len); - OPENSSL_free(bytes_buf); - return retval; -} - -/*[clinic input] -_ssl._test_decode_cert - path: object(converter="PyUnicode_FSConverter") - / - -[clinic start generated code]*/ - -static PyObject * -_ssl__test_decode_cert_impl(PyObject *module, PyObject *path) -/*[clinic end generated code: output=96becb9abb23c091 input=cdeaaf02d4346628]*/ -{ - PyObject *retval = NULL; - X509 *x=NULL; - BIO *cert; - - if ((cert=BIO_new(BIO_s_file())) == NULL) { - PyErr_SetString(PySSLErrorObject, - "Can't malloc memory to read file"); - goto fail0; - } - - if (BIO_read_filename(cert, PyBytes_AsString(path)) <= 0) { - PyErr_SetString(PySSLErrorObject, - "Can't open file"); - goto fail0; - } - - x = PEM_read_bio_X509_AUX(cert,NULL, NULL, NULL); - if (x == NULL) { - PyErr_SetString(PySSLErrorObject, - "Error decoding PEM-encoded file"); - goto fail0; - } - - retval = _decode_certificate(x); - X509_free(x); - - fail0: - Py_DECREF(path); - if (cert != NULL) BIO_free(cert); - return retval; -} - - -/*[clinic input] -_ssl._SSLSocket.peer_certificate - der as binary_mode: bool = False - / - -Returns the certificate for the peer. - -If no certificate was provided, returns None. If a certificate was -provided, but not validated, returns an empty dictionary. Otherwise -returns a dict containing information about the peer certificate. - -If the optional argument is True, returns a DER-encoded copy of the -peer certificate, or None if no certificate was provided. This will -return the certificate even if it wasn't validated. -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLSocket_peer_certificate_impl(PySSLSocket *self, int binary_mode) -/*[clinic end generated code: output=f0dc3e4d1d818a1d input=8281bd1d193db843]*/ -{ - int verification; - X509 *peer_cert; - PyObject *result; - - if (!SSL_is_init_finished(self->ssl)) { - PyErr_SetString(PyExc_ValueError, - "handshake not done yet"); - return NULL; - } - peer_cert = SSL_get_peer_certificate(self->ssl); - if (peer_cert == NULL) - Py_RETURN_NONE; - - if (binary_mode) { - /* return cert in DER-encoded format */ - result = _certificate_to_der(peer_cert); - } else { - verification = SSL_CTX_get_verify_mode(SSL_get_SSL_CTX(self->ssl)); - if ((verification & SSL_VERIFY_PEER) == 0) - result = PyDict_New(); - else - result = _decode_certificate(peer_cert); - } - X509_free(peer_cert); - return result; -} - -static PyObject * -cipher_to_tuple(const SSL_CIPHER *cipher) -{ - const char *cipher_name, *cipher_protocol; - PyObject *v, *retval = PyTuple_New(3); - if (retval == NULL) - return NULL; - - cipher_name = SSL_CIPHER_get_name(cipher); - if (cipher_name == NULL) { - Py_INCREF(Py_None); - PyTuple_SET_ITEM(retval, 0, Py_None); - } else { - v = PyUnicode_FromString(cipher_name); - if (v == NULL) - goto fail; - PyTuple_SET_ITEM(retval, 0, v); - } - - cipher_protocol = SSL_CIPHER_get_version(cipher); - if (cipher_protocol == NULL) { - Py_INCREF(Py_None); - PyTuple_SET_ITEM(retval, 1, Py_None); - } else { - v = PyUnicode_FromString(cipher_protocol); - if (v == NULL) - goto fail; - PyTuple_SET_ITEM(retval, 1, v); - } - - v = PyLong_FromLong(SSL_CIPHER_get_bits(cipher, NULL)); - if (v == NULL) - goto fail; - PyTuple_SET_ITEM(retval, 2, v); - - return retval; - - fail: - Py_DECREF(retval); - return NULL; -} - -#if OPENSSL_VERSION_NUMBER >= 0x10002000UL -static PyObject * -cipher_to_dict(const SSL_CIPHER *cipher) -{ - const char *cipher_name, *cipher_protocol; - - unsigned long cipher_id; - int alg_bits, strength_bits, len; - char buf[512] = {0}; -#if OPENSSL_VERSION_1_1 - int aead, nid; - const char *skcipher = NULL, *digest = NULL, *kx = NULL, *auth = NULL; -#endif - - /* can be NULL */ - cipher_name = SSL_CIPHER_get_name(cipher); - cipher_protocol = SSL_CIPHER_get_version(cipher); - cipher_id = SSL_CIPHER_get_id(cipher); - SSL_CIPHER_description(cipher, buf, sizeof(buf) - 1); - len = strlen(buf); - if (len > 1 && buf[len-1] == '\n') - buf[len-1] = '\0'; - strength_bits = SSL_CIPHER_get_bits(cipher, &alg_bits); - -#if OPENSSL_VERSION_1_1 - aead = SSL_CIPHER_is_aead(cipher); - nid = SSL_CIPHER_get_cipher_nid(cipher); - skcipher = nid != NID_undef ? OBJ_nid2ln(nid) : NULL; - nid = SSL_CIPHER_get_digest_nid(cipher); - digest = nid != NID_undef ? OBJ_nid2ln(nid) : NULL; - nid = SSL_CIPHER_get_kx_nid(cipher); - kx = nid != NID_undef ? OBJ_nid2ln(nid) : NULL; - nid = SSL_CIPHER_get_auth_nid(cipher); - auth = nid != NID_undef ? OBJ_nid2ln(nid) : NULL; -#endif - - return Py_BuildValue( - "{sksssssssisi" -#if OPENSSL_VERSION_1_1 - "sOssssssss" -#endif - "}", - "id", cipher_id, - "name", cipher_name, - "protocol", cipher_protocol, - "description", buf, - "strength_bits", strength_bits, - "alg_bits", alg_bits -#if OPENSSL_VERSION_1_1 - ,"aead", aead ? Py_True : Py_False, - "symmetric", skcipher, - "digest", digest, - "kea", kx, - "auth", auth -#endif - ); -} -#endif - -/*[clinic input] -_ssl._SSLSocket.shared_ciphers -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLSocket_shared_ciphers_impl(PySSLSocket *self) -/*[clinic end generated code: output=3d174ead2e42c4fd input=0bfe149da8fe6306]*/ -{ - STACK_OF(SSL_CIPHER) *ciphers; - int i; - PyObject *res; - - ciphers = SSL_get_ciphers(self->ssl); - if (!ciphers) - Py_RETURN_NONE; - res = PyList_New(sk_SSL_CIPHER_num(ciphers)); - if (!res) - return NULL; - for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) { - PyObject *tup = cipher_to_tuple(sk_SSL_CIPHER_value(ciphers, i)); - if (!tup) { - Py_DECREF(res); - return NULL; - } - PyList_SET_ITEM(res, i, tup); - } - return res; -} - -/*[clinic input] -_ssl._SSLSocket.cipher -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLSocket_cipher_impl(PySSLSocket *self) -/*[clinic end generated code: output=376417c16d0e5815 input=548fb0e27243796d]*/ -{ - const SSL_CIPHER *current; - - if (self->ssl == NULL) - Py_RETURN_NONE; - current = SSL_get_current_cipher(self->ssl); - if (current == NULL) - Py_RETURN_NONE; - return cipher_to_tuple(current); -} - -/*[clinic input] -_ssl._SSLSocket.version -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLSocket_version_impl(PySSLSocket *self) -/*[clinic end generated code: output=178aed33193b2cdb input=900186a503436fd6]*/ -{ - const char *version; - - if (self->ssl == NULL) - Py_RETURN_NONE; - if (!SSL_is_init_finished(self->ssl)) { - /* handshake not finished */ - Py_RETURN_NONE; - } - version = SSL_get_version(self->ssl); - if (!strcmp(version, "unknown")) - Py_RETURN_NONE; - return PyUnicode_FromString(version); -} - -#if HAVE_NPN -/*[clinic input] -_ssl._SSLSocket.selected_npn_protocol -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLSocket_selected_npn_protocol_impl(PySSLSocket *self) -/*[clinic end generated code: output=b91d494cd207ecf6 input=c28fde139204b826]*/ -{ - const unsigned char *out; - unsigned int outlen; - - SSL_get0_next_proto_negotiated(self->ssl, - &out, &outlen); - - if (out == NULL) - Py_RETURN_NONE; - return PyUnicode_FromStringAndSize((char *)out, outlen); -} -#endif - -#if HAVE_ALPN -/*[clinic input] -_ssl._SSLSocket.selected_alpn_protocol -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLSocket_selected_alpn_protocol_impl(PySSLSocket *self) -/*[clinic end generated code: output=ec33688b303d250f input=442de30e35bc2913]*/ -{ - const unsigned char *out; - unsigned int outlen; - - SSL_get0_alpn_selected(self->ssl, &out, &outlen); - - if (out == NULL) - Py_RETURN_NONE; - return PyUnicode_FromStringAndSize((char *)out, outlen); -} -#endif - -/*[clinic input] -_ssl._SSLSocket.compression -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLSocket_compression_impl(PySSLSocket *self) -/*[clinic end generated code: output=bd16cb1bb4646ae7 input=5d059d0a2bbc32c8]*/ -{ -#ifdef OPENSSL_NO_COMP - Py_RETURN_NONE; -#else - const COMP_METHOD *comp_method; - const char *short_name; - - if (self->ssl == NULL) - Py_RETURN_NONE; - comp_method = SSL_get_current_compression(self->ssl); - if (comp_method == NULL || COMP_get_type(comp_method) == NID_undef) - Py_RETURN_NONE; - short_name = OBJ_nid2sn(COMP_get_type(comp_method)); - if (short_name == NULL) - Py_RETURN_NONE; - return PyUnicode_DecodeFSDefault(short_name); -#endif -} - -static PySSLContext *PySSL_get_context(PySSLSocket *self, void *closure) { - Py_INCREF(self->ctx); - return self->ctx; -} - -static int PySSL_set_context(PySSLSocket *self, PyObject *value, - void *closure) { - - if (PyObject_TypeCheck(value, &PySSLContext_Type)) { -#if !HAVE_SNI - PyErr_SetString(PyExc_NotImplementedError, "setting a socket's " - "context is not supported by your OpenSSL library"); - return -1; -#else - Py_INCREF(value); - Py_SETREF(self->ctx, (PySSLContext *)value); - SSL_set_SSL_CTX(self->ssl, self->ctx->ctx); -#endif - } else { - PyErr_SetString(PyExc_TypeError, "The value must be a SSLContext"); - return -1; - } - - return 0; -} - -PyDoc_STRVAR(PySSL_set_context_doc, -"_setter_context(ctx)\n\ -\ -This changes the context associated with the SSLSocket. This is typically\n\ -used from within a callback function set by the set_servername_callback\n\ -on the SSLContext to change the certificate information associated with the\n\ -SSLSocket before the cryptographic exchange handshake messages\n"); - - -static PyObject * -PySSL_get_server_side(PySSLSocket *self, void *c) -{ - return PyBool_FromLong(self->socket_type == PY_SSL_SERVER); -} - -PyDoc_STRVAR(PySSL_get_server_side_doc, -"Whether this is a server-side socket."); - -static PyObject * -PySSL_get_server_hostname(PySSLSocket *self, void *c) -{ - if (self->server_hostname == NULL) - Py_RETURN_NONE; - Py_INCREF(self->server_hostname); - return self->server_hostname; -} - -PyDoc_STRVAR(PySSL_get_server_hostname_doc, -"The currently set server hostname (for SNI)."); - -static PyObject * -PySSL_get_owner(PySSLSocket *self, void *c) -{ - PyObject *owner; - - if (self->owner == NULL) - Py_RETURN_NONE; - - owner = PyWeakref_GetObject(self->owner); - Py_INCREF(owner); - return owner; -} - -static int -PySSL_set_owner(PySSLSocket *self, PyObject *value, void *c) -{ - Py_XSETREF(self->owner, PyWeakref_NewRef(value, NULL)); - if (self->owner == NULL) - return -1; - return 0; -} - -PyDoc_STRVAR(PySSL_get_owner_doc, -"The Python-level owner of this object.\ -Passed as \"self\" in servername callback."); - - -static void PySSL_dealloc(PySSLSocket *self) -{ - if (self->ssl) - SSL_free(self->ssl); - Py_XDECREF(self->Socket); - Py_XDECREF(self->ctx); - Py_XDECREF(self->server_hostname); - Py_XDECREF(self->owner); - PyObject_Del(self); -} - -/* If the socket has a timeout, do a select()/poll() on the socket. - The argument writing indicates the direction. - Returns one of the possibilities in the timeout_state enum (above). - */ - -static int -PySSL_select(PySocketSockObject *s, int writing, _PyTime_t timeout) -{ - int rc; -#ifdef HAVE_POLL - struct pollfd pollfd; - _PyTime_t ms; -#else - int nfds; - fd_set fds; - struct timeval tv; -#endif - - /* Nothing to do unless we're in timeout mode (not non-blocking) */ - if ((s == NULL) || (timeout == 0)) - return SOCKET_IS_NONBLOCKING; - else if (timeout < 0) { - if (s->sock_timeout > 0) - return SOCKET_HAS_TIMED_OUT; - else - return SOCKET_IS_BLOCKING; - } - - /* Guard against closed socket */ - if (s->sock_fd == INVALID_SOCKET) - return SOCKET_HAS_BEEN_CLOSED; - - /* Prefer poll, if available, since you can poll() any fd - * which can't be done with select(). */ -#ifdef HAVE_POLL - pollfd.fd = s->sock_fd; - pollfd.events = writing ? POLLOUT : POLLIN; - - /* timeout is in seconds, poll() uses milliseconds */ - ms = (int)_PyTime_AsMilliseconds(timeout, _PyTime_ROUND_CEILING); - assert(ms <= INT_MAX); - - PySSL_BEGIN_ALLOW_THREADS - rc = poll(&pollfd, 1, (int)ms); - PySSL_END_ALLOW_THREADS -#else - /* Guard against socket too large for select*/ - if (!_PyIsSelectable_fd(s->sock_fd)) - return SOCKET_TOO_LARGE_FOR_SELECT; - - _PyTime_AsTimeval_noraise(timeout, &tv, _PyTime_ROUND_CEILING); - - FD_ZERO(&fds); - FD_SET(s->sock_fd, &fds); - - /* Wait until the socket becomes ready */ - PySSL_BEGIN_ALLOW_THREADS - nfds = Py_SAFE_DOWNCAST(s->sock_fd+1, SOCKET_T, int); - if (writing) - rc = select(nfds, NULL, &fds, NULL, &tv); - else - rc = select(nfds, &fds, NULL, NULL, &tv); - PySSL_END_ALLOW_THREADS -#endif - - /* Return SOCKET_TIMED_OUT on timeout, SOCKET_OPERATION_OK otherwise - (when we are able to write or when there's something to read) */ - return rc == 0 ? SOCKET_HAS_TIMED_OUT : SOCKET_OPERATION_OK; -} - -/*[clinic input] -_ssl._SSLSocket.write - b: Py_buffer - / - -Writes the bytes-like object b into the SSL object. - -Returns the number of bytes written. -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLSocket_write_impl(PySSLSocket *self, Py_buffer *b) -/*[clinic end generated code: output=aa7a6be5527358d8 input=77262d994fe5100a]*/ -{ - int len; - int sockstate; - _PySSLError err; - int nonblocking; - PySocketSockObject *sock = GET_SOCKET(self); - _PyTime_t timeout, deadline = 0; - int has_timeout; - - if (sock != NULL) { - if (((PyObject*)sock) == Py_None) { - _setSSLError("Underlying socket connection gone", - PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__); - return NULL; - } - Py_INCREF(sock); - } - - if (b->len > INT_MAX) { - PyErr_Format(PyExc_OverflowError, - "string longer than %d bytes", INT_MAX); - goto error; - } - - if (sock != NULL) { - /* just in case the blocking state of the socket has been changed */ - nonblocking = (sock->sock_timeout >= 0); - BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking); - BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking); - } - - timeout = GET_SOCKET_TIMEOUT(sock); - has_timeout = (timeout > 0); - if (has_timeout) - deadline = _PyTime_GetMonotonicClock() + timeout; - - sockstate = PySSL_select(sock, 1, timeout); - if (sockstate == SOCKET_HAS_TIMED_OUT) { - PyErr_SetString(PySocketModule.timeout_error, - "The write operation timed out"); - goto error; - } else if (sockstate == SOCKET_HAS_BEEN_CLOSED) { - PyErr_SetString(PySSLErrorObject, - "Underlying socket has been closed."); - goto error; - } else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) { - PyErr_SetString(PySSLErrorObject, - "Underlying socket too large for select()."); - goto error; - } - - do { - PySSL_BEGIN_ALLOW_THREADS - len = SSL_write(self->ssl, b->buf, (int)b->len); - err = _PySSL_errno(len <= 0, self->ssl, len); - PySSL_END_ALLOW_THREADS - self->err = err; - - if (PyErr_CheckSignals()) - goto error; - - if (has_timeout) - timeout = deadline - _PyTime_GetMonotonicClock(); - - if (err.ssl == SSL_ERROR_WANT_READ) { - sockstate = PySSL_select(sock, 0, timeout); - } else if (err.ssl == SSL_ERROR_WANT_WRITE) { - sockstate = PySSL_select(sock, 1, timeout); - } else { - sockstate = SOCKET_OPERATION_OK; - } - - if (sockstate == SOCKET_HAS_TIMED_OUT) { - PyErr_SetString(PySocketModule.timeout_error, - "The write operation timed out"); - goto error; - } else if (sockstate == SOCKET_HAS_BEEN_CLOSED) { - PyErr_SetString(PySSLErrorObject, - "Underlying socket has been closed."); - goto error; - } else if (sockstate == SOCKET_IS_NONBLOCKING) { - break; - } - } while (err.ssl == SSL_ERROR_WANT_READ || - err.ssl == SSL_ERROR_WANT_WRITE); - - Py_XDECREF(sock); - if (len > 0) - return PyLong_FromLong(len); - else - return PySSL_SetError(self, len, __FILE__, __LINE__); - -error: - Py_XDECREF(sock); - return NULL; -} - -/*[clinic input] -_ssl._SSLSocket.pending - -Returns the number of already decrypted bytes available for read, pending on the connection. -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLSocket_pending_impl(PySSLSocket *self) -/*[clinic end generated code: output=983d9fecdc308a83 input=2b77487d6dfd597f]*/ -{ - int count = 0; - _PySSLError err; - - PySSL_BEGIN_ALLOW_THREADS - count = SSL_pending(self->ssl); - err = _PySSL_errno(count < 0, self->ssl, count); - PySSL_END_ALLOW_THREADS - self->err = err; - - if (count < 0) - return PySSL_SetError(self, count, __FILE__, __LINE__); - else - return PyLong_FromLong(count); -} - -/*[clinic input] -_ssl._SSLSocket.read - size as len: int - [ - buffer: Py_buffer(accept={rwbuffer}) - ] - / - -Read up to size bytes from the SSL socket. -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLSocket_read_impl(PySSLSocket *self, int len, int group_right_1, - Py_buffer *buffer) -/*[clinic end generated code: output=00097776cec2a0af input=ff157eb918d0905b]*/ -{ - PyObject *dest = NULL; - char *mem; - int count; - int sockstate; - _PySSLError err; - int nonblocking; - PySocketSockObject *sock = GET_SOCKET(self); - _PyTime_t timeout, deadline = 0; - int has_timeout; - - if (!group_right_1 && len < 0) { - PyErr_SetString(PyExc_ValueError, "size should not be negative"); - return NULL; - } - - if (sock != NULL) { - if (((PyObject*)sock) == Py_None) { - _setSSLError("Underlying socket connection gone", - PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__); - return NULL; - } - Py_INCREF(sock); - } - - if (!group_right_1) { - dest = PyBytes_FromStringAndSize(NULL, len); - if (dest == NULL) - goto error; - if (len == 0) { - Py_XDECREF(sock); - return dest; - } - mem = PyBytes_AS_STRING(dest); - } - else { - mem = buffer->buf; - if (len <= 0 || len > buffer->len) { - len = (int) buffer->len; - if (buffer->len != len) { - PyErr_SetString(PyExc_OverflowError, - "maximum length can't fit in a C 'int'"); - goto error; - } - if (len == 0) { - count = 0; - goto done; - } - } - } - - if (sock != NULL) { - /* just in case the blocking state of the socket has been changed */ - nonblocking = (sock->sock_timeout >= 0); - BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking); - BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking); - } - - timeout = GET_SOCKET_TIMEOUT(sock); - has_timeout = (timeout > 0); - if (has_timeout) - deadline = _PyTime_GetMonotonicClock() + timeout; - - do { - PySSL_BEGIN_ALLOW_THREADS - count = SSL_read(self->ssl, mem, len); - err = _PySSL_errno(count <= 0, self->ssl, count); - PySSL_END_ALLOW_THREADS - self->err = err; - - if (PyErr_CheckSignals()) - goto error; - - if (has_timeout) - timeout = deadline - _PyTime_GetMonotonicClock(); - - if (err.ssl == SSL_ERROR_WANT_READ) { - sockstate = PySSL_select(sock, 0, timeout); - } else if (err.ssl == SSL_ERROR_WANT_WRITE) { - sockstate = PySSL_select(sock, 1, timeout); - } else if (err.ssl == SSL_ERROR_ZERO_RETURN && - SSL_get_shutdown(self->ssl) == SSL_RECEIVED_SHUTDOWN) - { - count = 0; - goto done; - } - else - sockstate = SOCKET_OPERATION_OK; - - if (sockstate == SOCKET_HAS_TIMED_OUT) { - PyErr_SetString(PySocketModule.timeout_error, - "The read operation timed out"); - goto error; - } else if (sockstate == SOCKET_IS_NONBLOCKING) { - break; - } - } while (err.ssl == SSL_ERROR_WANT_READ || - err.ssl == SSL_ERROR_WANT_WRITE); - - if (count <= 0) { - PySSL_SetError(self, count, __FILE__, __LINE__); - goto error; - } - -done: - Py_XDECREF(sock); - if (!group_right_1) { - _PyBytes_Resize(&dest, count); - return dest; - } - else { - return PyLong_FromLong(count); - } - -error: - Py_XDECREF(sock); - if (!group_right_1) - Py_XDECREF(dest); - return NULL; -} - -/*[clinic input] -_ssl._SSLSocket.shutdown - -Does the SSL shutdown handshake with the remote end. - -Returns the underlying socket object. -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLSocket_shutdown_impl(PySSLSocket *self) -/*[clinic end generated code: output=ca1aa7ed9d25ca42 input=ede2cc1a2ddf0ee4]*/ -{ - _PySSLError err; - int sockstate, nonblocking, ret; - int zeros = 0; - PySocketSockObject *sock = GET_SOCKET(self); - _PyTime_t timeout, deadline = 0; - int has_timeout; - - if (sock != NULL) { - /* Guard against closed socket */ - if ((((PyObject*)sock) == Py_None) || (sock->sock_fd == INVALID_SOCKET)) { - _setSSLError("Underlying socket connection gone", - PY_SSL_ERROR_NO_SOCKET, __FILE__, __LINE__); - return NULL; - } - Py_INCREF(sock); - - /* Just in case the blocking state of the socket has been changed */ - nonblocking = (sock->sock_timeout >= 0); - BIO_set_nbio(SSL_get_rbio(self->ssl), nonblocking); - BIO_set_nbio(SSL_get_wbio(self->ssl), nonblocking); - } - - timeout = GET_SOCKET_TIMEOUT(sock); - has_timeout = (timeout > 0); - if (has_timeout) - deadline = _PyTime_GetMonotonicClock() + timeout; - - while (1) { - PySSL_BEGIN_ALLOW_THREADS - /* Disable read-ahead so that unwrap can work correctly. - * Otherwise OpenSSL might read in too much data, - * eating clear text data that happens to be - * transmitted after the SSL shutdown. - * Should be safe to call repeatedly every time this - * function is used and the shutdown_seen_zero != 0 - * condition is met. - */ - if (self->shutdown_seen_zero) - SSL_set_read_ahead(self->ssl, 0); - ret = SSL_shutdown(self->ssl); - err = _PySSL_errno(ret < 0, self->ssl, ret); - PySSL_END_ALLOW_THREADS - self->err = err; - - /* If err == 1, a secure shutdown with SSL_shutdown() is complete */ - if (ret > 0) - break; - if (ret == 0) { - /* Don't loop endlessly; instead preserve legacy - behaviour of trying SSL_shutdown() only twice. - This looks necessary for OpenSSL < 0.9.8m */ - if (++zeros > 1) - break; - /* Shutdown was sent, now try receiving */ - self->shutdown_seen_zero = 1; - continue; - } - - if (has_timeout) - timeout = deadline - _PyTime_GetMonotonicClock(); - - /* Possibly retry shutdown until timeout or failure */ - if (err.ssl == SSL_ERROR_WANT_READ) - sockstate = PySSL_select(sock, 0, timeout); - else if (err.ssl == SSL_ERROR_WANT_WRITE) - sockstate = PySSL_select(sock, 1, timeout); - else - break; - - if (sockstate == SOCKET_HAS_TIMED_OUT) { - if (err.ssl == SSL_ERROR_WANT_READ) - PyErr_SetString(PySocketModule.timeout_error, - "The read operation timed out"); - else - PyErr_SetString(PySocketModule.timeout_error, - "The write operation timed out"); - goto error; - } - else if (sockstate == SOCKET_TOO_LARGE_FOR_SELECT) { - PyErr_SetString(PySSLErrorObject, - "Underlying socket too large for select()."); - goto error; - } - else if (sockstate != SOCKET_OPERATION_OK) - /* Retain the SSL error code */ - break; - } - - if (ret < 0) { - Py_XDECREF(sock); - return PySSL_SetError(self, ret, __FILE__, __LINE__); - } - if (sock) - /* It's already INCREF'ed */ - return (PyObject *) sock; - else - Py_RETURN_NONE; - -error: - Py_XDECREF(sock); - return NULL; -} - -/*[clinic input] -_ssl._SSLSocket.tls_unique_cb - -Returns the 'tls-unique' channel binding data, as defined by RFC 5929. - -If the TLS handshake is not yet complete, None is returned. -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLSocket_tls_unique_cb_impl(PySSLSocket *self) -/*[clinic end generated code: output=f3a832d603f586af input=439525c7b3d8d34d]*/ -{ - PyObject *retval = NULL; - char buf[PySSL_CB_MAXLEN]; - size_t len; - - if (SSL_session_reused(self->ssl) ^ !self->socket_type) { - /* if session is resumed XOR we are the client */ - len = SSL_get_finished(self->ssl, buf, PySSL_CB_MAXLEN); - } - else { - /* if a new session XOR we are the server */ - len = SSL_get_peer_finished(self->ssl, buf, PySSL_CB_MAXLEN); - } - - /* It cannot be negative in current OpenSSL version as of July 2011 */ - if (len == 0) - Py_RETURN_NONE; - - retval = PyBytes_FromStringAndSize(buf, len); - - return retval; -} - -/*[clinic input] -_ssl._SSLSocket.verify_client_post_handshake - -Initiate TLS 1.3 post-handshake authentication -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLSocket_verify_client_post_handshake_impl(PySSLSocket *self) -/*[clinic end generated code: output=532147f3b1341425 input=6bfa874810a3d889]*/ -{ -#ifdef TLS1_3_VERSION - int err = SSL_verify_client_post_handshake(self->ssl); - if (err == 0) - return _setSSLError(NULL, 0, __FILE__, __LINE__); - else - Py_RETURN_NONE; -#else - PyErr_SetString(PyExc_NotImplementedError, - "Post-handshake auth is not supported by your " - "OpenSSL version."); - return NULL; -#endif -} - -#ifdef OPENSSL_VERSION_1_1 - -static SSL_SESSION* -_ssl_session_dup(SSL_SESSION *session) { - SSL_SESSION *newsession = NULL; - int slen; - unsigned char *senc = NULL, *p; - const unsigned char *const_p; - - if (session == NULL) { - PyErr_SetString(PyExc_ValueError, "Invalid session"); - goto error; - } - - /* get length */ - slen = i2d_SSL_SESSION(session, NULL); - if (slen == 0 || slen > 0xFF00) { - PyErr_SetString(PyExc_ValueError, "i2d() failed."); - goto error; - } - if ((senc = PyMem_Malloc(slen)) == NULL) { - PyErr_NoMemory(); - goto error; - } - p = senc; - if (!i2d_SSL_SESSION(session, &p)) { - PyErr_SetString(PyExc_ValueError, "i2d() failed."); - goto error; - } - const_p = senc; - newsession = d2i_SSL_SESSION(NULL, &const_p, slen); - if (session == NULL) { - goto error; - } - PyMem_Free(senc); - return newsession; - error: - if (senc != NULL) { - PyMem_Free(senc); - } - return NULL; -} -#endif - -static PyObject * -PySSL_get_session(PySSLSocket *self, void *closure) { - /* get_session can return sessions from a server-side connection, - * it does not check for handshake done or client socket. */ - PySSLSession *pysess; - SSL_SESSION *session; - -#ifdef OPENSSL_VERSION_1_1 - /* duplicate session as workaround for session bug in OpenSSL 1.1.0, - * https://github.com/openssl/openssl/issues/1550 */ - session = SSL_get0_session(self->ssl); /* borrowed reference */ - if (session == NULL) { - Py_RETURN_NONE; - } - if ((session = _ssl_session_dup(session)) == NULL) { - return NULL; - } -#else - session = SSL_get1_session(self->ssl); - if (session == NULL) { - Py_RETURN_NONE; - } -#endif - pysess = PyObject_GC_New(PySSLSession, &PySSLSession_Type); - if (pysess == NULL) { - SSL_SESSION_free(session); - return NULL; - } - - assert(self->ctx); - pysess->ctx = self->ctx; - Py_INCREF(pysess->ctx); - pysess->session = session; - PyObject_GC_Track(pysess); - return (PyObject *)pysess; -} - -static int PySSL_set_session(PySSLSocket *self, PyObject *value, - void *closure) - { - PySSLSession *pysess; -#ifdef OPENSSL_VERSION_1_1 - SSL_SESSION *session; -#endif - int result; - - if (!PySSLSession_Check(value)) { - PyErr_SetString(PyExc_TypeError, "Value is not a SSLSession."); - return -1; - } - pysess = (PySSLSession *)value; - - if (self->ctx->ctx != pysess->ctx->ctx) { - PyErr_SetString(PyExc_ValueError, - "Session refers to a different SSLContext."); - return -1; - } - if (self->socket_type != PY_SSL_CLIENT) { - PyErr_SetString(PyExc_ValueError, - "Cannot set session for server-side SSLSocket."); - return -1; - } - if (SSL_is_init_finished(self->ssl)) { - PyErr_SetString(PyExc_ValueError, - "Cannot set session after handshake."); - return -1; - } -#ifdef OPENSSL_VERSION_1_1 - /* duplicate session */ - if ((session = _ssl_session_dup(pysess->session)) == NULL) { - return -1; - } - result = SSL_set_session(self->ssl, session); - /* free duplicate, SSL_set_session() bumps ref count */ - SSL_SESSION_free(session); -#else - result = SSL_set_session(self->ssl, pysess->session); -#endif - if (result == 0) { - _setSSLError(NULL, 0, __FILE__, __LINE__); - return -1; - } - return 0; -} - -PyDoc_STRVAR(PySSL_set_session_doc, -"_setter_session(session)\n\ -\ -Get / set SSLSession."); - -static PyObject * -PySSL_get_session_reused(PySSLSocket *self, void *closure) { - if (SSL_session_reused(self->ssl)) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyDoc_STRVAR(PySSL_get_session_reused_doc, -"Was the client session reused during handshake?"); - -static PyGetSetDef ssl_getsetlist[] = { - {"context", (getter) PySSL_get_context, - (setter) PySSL_set_context, PySSL_set_context_doc}, - {"server_side", (getter) PySSL_get_server_side, NULL, - PySSL_get_server_side_doc}, - {"server_hostname", (getter) PySSL_get_server_hostname, NULL, - PySSL_get_server_hostname_doc}, - {"owner", (getter) PySSL_get_owner, (setter) PySSL_set_owner, - PySSL_get_owner_doc}, - {"session", (getter) PySSL_get_session, - (setter) PySSL_set_session, PySSL_set_session_doc}, - {"session_reused", (getter) PySSL_get_session_reused, NULL, - PySSL_get_session_reused_doc}, - {NULL}, /* sentinel */ -}; - -static PyMethodDef PySSLMethods[] = { - _SSL__SSLSOCKET_DO_HANDSHAKE_METHODDEF - _SSL__SSLSOCKET_WRITE_METHODDEF - _SSL__SSLSOCKET_READ_METHODDEF - _SSL__SSLSOCKET_PENDING_METHODDEF - _SSL__SSLSOCKET_PEER_CERTIFICATE_METHODDEF - _SSL__SSLSOCKET_CIPHER_METHODDEF - _SSL__SSLSOCKET_SHARED_CIPHERS_METHODDEF - _SSL__SSLSOCKET_VERSION_METHODDEF - _SSL__SSLSOCKET_SELECTED_NPN_PROTOCOL_METHODDEF - _SSL__SSLSOCKET_SELECTED_ALPN_PROTOCOL_METHODDEF - _SSL__SSLSOCKET_COMPRESSION_METHODDEF - _SSL__SSLSOCKET_SHUTDOWN_METHODDEF - _SSL__SSLSOCKET_TLS_UNIQUE_CB_METHODDEF - _SSL__SSLSOCKET_VERIFY_CLIENT_POST_HANDSHAKE_METHODDEF - {NULL, NULL} -}; - -static PyTypeObject PySSLSocket_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ssl._SSLSocket", /*tp_name*/ - sizeof(PySSLSocket), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - /* methods */ - (destructor)PySSL_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_reserved*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT, /*tp_flags*/ - 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - PySSLMethods, /*tp_methods*/ - 0, /*tp_members*/ - ssl_getsetlist, /*tp_getset*/ -}; - - -/* - * _SSLContext objects - */ - -static int -_set_verify_mode(PySSLContext *self, enum py_ssl_cert_requirements n) -{ - int mode; - int (*verify_cb)(int, X509_STORE_CTX *) = NULL; - - switch(n) { - case PY_SSL_CERT_NONE: - mode = SSL_VERIFY_NONE; - break; - case PY_SSL_CERT_OPTIONAL: - mode = SSL_VERIFY_PEER; - break; - case PY_SSL_CERT_REQUIRED: - mode = SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT; - break; - default: - PyErr_SetString(PyExc_ValueError, - "invalid value for verify_mode"); - return -1; - } -#ifdef TLS1_3_VERSION - if (self->post_handshake_auth) - mode |= SSL_VERIFY_POST_HANDSHAKE; -#endif - /* keep current verify cb */ - verify_cb = SSL_CTX_get_verify_callback(self->ctx); - SSL_CTX_set_verify(self->ctx, mode, verify_cb); - return 0; -} - -/*[clinic input] -@classmethod -_ssl._SSLContext.__new__ - protocol as proto_version: int - / -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLContext_impl(PyTypeObject *type, int proto_version) -/*[clinic end generated code: output=2cf0d7a0741b6bd1 input=8d58a805b95fc534]*/ -{ - PySSLContext *self; - long options; - SSL_CTX *ctx = NULL; - int result; -#if defined(SSL_MODE_RELEASE_BUFFERS) - unsigned long libver; -#endif - - PySSL_BEGIN_ALLOW_THREADS - if (proto_version == PY_SSL_VERSION_TLS1) - ctx = SSL_CTX_new(TLSv1_method()); -#if HAVE_TLSv1_2 - else if (proto_version == PY_SSL_VERSION_TLS1_1) - ctx = SSL_CTX_new(TLSv1_1_method()); - else if (proto_version == PY_SSL_VERSION_TLS1_2) - ctx = SSL_CTX_new(TLSv1_2_method()); -#endif -#ifndef OPENSSL_NO_SSL3 - else if (proto_version == PY_SSL_VERSION_SSL3) - ctx = SSL_CTX_new(SSLv3_method()); -#endif -#ifndef OPENSSL_NO_SSL2 - else if (proto_version == PY_SSL_VERSION_SSL2) - ctx = SSL_CTX_new(SSLv2_method()); -#endif - else if (proto_version == PY_SSL_VERSION_TLS) /* SSLv23 */ - ctx = SSL_CTX_new(TLS_method()); - else if (proto_version == PY_SSL_VERSION_TLS_CLIENT) - ctx = SSL_CTX_new(TLS_client_method()); - else if (proto_version == PY_SSL_VERSION_TLS_SERVER) - ctx = SSL_CTX_new(TLS_server_method()); - else - proto_version = -1; - PySSL_END_ALLOW_THREADS - - if (proto_version == -1) { - PyErr_SetString(PyExc_ValueError, - "invalid protocol version"); - return NULL; - } - if (ctx == NULL) { - _setSSLError(NULL, 0, __FILE__, __LINE__); - return NULL; - } - - assert(type != NULL && type->tp_alloc != NULL); - self = (PySSLContext *) type->tp_alloc(type, 0); - if (self == NULL) { - SSL_CTX_free(ctx); - return NULL; - } - self->ctx = ctx; -#if HAVE_NPN - self->npn_protocols = NULL; -#endif -#if HAVE_ALPN - self->alpn_protocols = NULL; -#endif -#ifndef OPENSSL_NO_TLSEXT - self->set_hostname = NULL; -#endif - /* Don't check host name by default */ - if (proto_version == PY_SSL_VERSION_TLS_CLIENT) { - self->check_hostname = 1; - if (_set_verify_mode(self, PY_SSL_CERT_REQUIRED) == -1) { - Py_DECREF(self); - return NULL; - } - } else { - self->check_hostname = 0; - if (_set_verify_mode(self, PY_SSL_CERT_NONE) == -1) { - Py_DECREF(self); - return NULL; - } - } - /* Defaults */ - options = SSL_OP_ALL & ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS; - if (proto_version != PY_SSL_VERSION_SSL2) - options |= SSL_OP_NO_SSLv2; - if (proto_version != PY_SSL_VERSION_SSL3) - options |= SSL_OP_NO_SSLv3; - /* Minimal security flags for server and client side context. - * Client sockets ignore server-side parameters. */ -#ifdef SSL_OP_NO_COMPRESSION - options |= SSL_OP_NO_COMPRESSION; -#endif -#ifdef SSL_OP_CIPHER_SERVER_PREFERENCE - options |= SSL_OP_CIPHER_SERVER_PREFERENCE; -#endif -#ifdef SSL_OP_SINGLE_DH_USE - options |= SSL_OP_SINGLE_DH_USE; -#endif -#ifdef SSL_OP_SINGLE_ECDH_USE - options |= SSL_OP_SINGLE_ECDH_USE; -#endif - SSL_CTX_set_options(self->ctx, options); - - /* A bare minimum cipher list without completely broken cipher suites. - * It's far from perfect but gives users a better head start. */ - if (proto_version != PY_SSL_VERSION_SSL2) { - result = SSL_CTX_set_cipher_list(ctx, "HIGH:!aNULL:!eNULL:!MD5"); - } else { - /* SSLv2 needs MD5 */ - result = SSL_CTX_set_cipher_list(ctx, "HIGH:!aNULL:!eNULL"); - } - if (result == 0) { - Py_DECREF(self); - ERR_clear_error(); - PyErr_SetString(PySSLErrorObject, - "No cipher can be selected."); - return NULL; - } - -#if defined(SSL_MODE_RELEASE_BUFFERS) - /* Set SSL_MODE_RELEASE_BUFFERS. This potentially greatly reduces memory - usage for no cost at all. However, don't do this for OpenSSL versions - between 1.0.1 and 1.0.1h or 1.0.0 and 1.0.0m, which are affected by CVE - 2014-0198. I can't find exactly which beta fixed this CVE, so be - conservative and assume it wasn't fixed until release. We do this check - at runtime to avoid problems from the dynamic linker. - See #25672 for more on this. */ - libver = SSLeay(); - if (!(libver >= 0x10001000UL && libver < 0x1000108fUL) && - !(libver >= 0x10000000UL && libver < 0x100000dfUL)) { - SSL_CTX_set_mode(self->ctx, SSL_MODE_RELEASE_BUFFERS); - } -#endif - - -#if !defined(OPENSSL_NO_ECDH) && !defined(OPENSSL_VERSION_1_1) - /* Allow automatic ECDH curve selection (on OpenSSL 1.0.2+), or use - prime256v1 by default. This is Apache mod_ssl's initialization - policy, so we should be safe. OpenSSL 1.1 has it enabled by default. - */ -#if defined(SSL_CTX_set_ecdh_auto) - SSL_CTX_set_ecdh_auto(self->ctx, 1); -#else - { - EC_KEY *key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); - SSL_CTX_set_tmp_ecdh(self->ctx, key); - EC_KEY_free(key); - } -#endif -#endif - -#define SID_CTX "Python" - SSL_CTX_set_session_id_context(self->ctx, (const unsigned char *) SID_CTX, - sizeof(SID_CTX)); -#undef SID_CTX - -#ifdef X509_V_FLAG_TRUSTED_FIRST - { - /* Improve trust chain building when cross-signed intermediate - certificates are present. See https://bugs.python.org/issue23476. */ - X509_STORE *store = SSL_CTX_get_cert_store(self->ctx); - X509_STORE_set_flags(store, X509_V_FLAG_TRUSTED_FIRST); - } -#endif - -#ifdef TLS1_3_VERSION - self->post_handshake_auth = 0; - SSL_CTX_set_post_handshake_auth(self->ctx, self->post_handshake_auth); -#endif - - return (PyObject *)self; -} - -static int -context_traverse(PySSLContext *self, visitproc visit, void *arg) -{ -#ifndef OPENSSL_NO_TLSEXT - Py_VISIT(self->set_hostname); -#endif - return 0; -} - -static int -context_clear(PySSLContext *self) -{ -#ifndef OPENSSL_NO_TLSEXT - Py_CLEAR(self->set_hostname); -#endif - return 0; -} - -static void -context_dealloc(PySSLContext *self) -{ - /* bpo-31095: UnTrack is needed before calling any callbacks */ - PyObject_GC_UnTrack(self); - context_clear(self); - SSL_CTX_free(self->ctx); -#if HAVE_NPN - PyMem_FREE(self->npn_protocols); -#endif -#if HAVE_ALPN - PyMem_FREE(self->alpn_protocols); -#endif - Py_TYPE(self)->tp_free(self); -} - -/*[clinic input] -_ssl._SSLContext.set_ciphers - cipherlist: str - / -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLContext_set_ciphers_impl(PySSLContext *self, const char *cipherlist) -/*[clinic end generated code: output=3a3162f3557c0f3f input=a7ac931b9f3ca7fc]*/ -{ - int ret = SSL_CTX_set_cipher_list(self->ctx, cipherlist); - if (ret == 0) { - /* Clearing the error queue is necessary on some OpenSSL versions, - otherwise the error will be reported again when another SSL call - is done. */ - ERR_clear_error(); - PyErr_SetString(PySSLErrorObject, - "No cipher can be selected."); - return NULL; - } - Py_RETURN_NONE; -} - -#if OPENSSL_VERSION_NUMBER >= 0x10002000UL -/*[clinic input] -_ssl._SSLContext.get_ciphers -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLContext_get_ciphers_impl(PySSLContext *self) -/*[clinic end generated code: output=a56e4d68a406dfc4 input=a2aadc9af89b79c5]*/ -{ - SSL *ssl = NULL; - STACK_OF(SSL_CIPHER) *sk = NULL; - const SSL_CIPHER *cipher; - int i=0; - PyObject *result = NULL, *dct; - - ssl = SSL_new(self->ctx); - if (ssl == NULL) { - _setSSLError(NULL, 0, __FILE__, __LINE__); - goto exit; - } - sk = SSL_get_ciphers(ssl); - - result = PyList_New(sk_SSL_CIPHER_num(sk)); - if (result == NULL) { - goto exit; - } - - for (i = 0; i < sk_SSL_CIPHER_num(sk); i++) { - cipher = sk_SSL_CIPHER_value(sk, i); - dct = cipher_to_dict(cipher); - if (dct == NULL) { - Py_CLEAR(result); - goto exit; - } - PyList_SET_ITEM(result, i, dct); - } - - exit: - if (ssl != NULL) - SSL_free(ssl); - return result; - -} -#endif - - -#if HAVE_NPN || HAVE_ALPN -static int -do_protocol_selection(int alpn, unsigned char **out, unsigned char *outlen, - const unsigned char *server_protocols, unsigned int server_protocols_len, - const unsigned char *client_protocols, unsigned int client_protocols_len) -{ - int ret; - if (client_protocols == NULL) { - client_protocols = (unsigned char *)""; - client_protocols_len = 0; - } - if (server_protocols == NULL) { - server_protocols = (unsigned char *)""; - server_protocols_len = 0; - } - - ret = SSL_select_next_proto(out, outlen, - server_protocols, server_protocols_len, - client_protocols, client_protocols_len); - if (alpn && ret != OPENSSL_NPN_NEGOTIATED) - return SSL_TLSEXT_ERR_NOACK; - - return SSL_TLSEXT_ERR_OK; -} -#endif - -#if HAVE_NPN -/* this callback gets passed to SSL_CTX_set_next_protos_advertise_cb */ -static int -_advertiseNPN_cb(SSL *s, - const unsigned char **data, unsigned int *len, - void *args) -{ - PySSLContext *ssl_ctx = (PySSLContext *) args; - - if (ssl_ctx->npn_protocols == NULL) { - *data = (unsigned char *)""; - *len = 0; - } else { - *data = ssl_ctx->npn_protocols; - *len = ssl_ctx->npn_protocols_len; - } - - return SSL_TLSEXT_ERR_OK; -} -/* this callback gets passed to SSL_CTX_set_next_proto_select_cb */ -static int -_selectNPN_cb(SSL *s, - unsigned char **out, unsigned char *outlen, - const unsigned char *server, unsigned int server_len, - void *args) -{ - PySSLContext *ctx = (PySSLContext *)args; - return do_protocol_selection(0, out, outlen, server, server_len, - ctx->npn_protocols, ctx->npn_protocols_len); -} -#endif - -/*[clinic input] -_ssl._SSLContext._set_npn_protocols - protos: Py_buffer - / -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLContext__set_npn_protocols_impl(PySSLContext *self, - Py_buffer *protos) -/*[clinic end generated code: output=72b002c3324390c6 input=319fcb66abf95bd7]*/ -{ -#if HAVE_NPN - PyMem_Free(self->npn_protocols); - self->npn_protocols = PyMem_Malloc(protos->len); - if (self->npn_protocols == NULL) - return PyErr_NoMemory(); - memcpy(self->npn_protocols, protos->buf, protos->len); - self->npn_protocols_len = (int) protos->len; - - /* set both server and client callbacks, because the context can - * be used to create both types of sockets */ - SSL_CTX_set_next_protos_advertised_cb(self->ctx, - _advertiseNPN_cb, - self); - SSL_CTX_set_next_proto_select_cb(self->ctx, - _selectNPN_cb, - self); - - Py_RETURN_NONE; -#else - PyErr_SetString(PyExc_NotImplementedError, - "The NPN extension requires OpenSSL 1.0.1 or later."); - return NULL; -#endif -} - -#if HAVE_ALPN -static int -_selectALPN_cb(SSL *s, - const unsigned char **out, unsigned char *outlen, - const unsigned char *client_protocols, unsigned int client_protocols_len, - void *args) -{ - PySSLContext *ctx = (PySSLContext *)args; - return do_protocol_selection(1, (unsigned char **)out, outlen, - ctx->alpn_protocols, ctx->alpn_protocols_len, - client_protocols, client_protocols_len); -} -#endif - -/*[clinic input] -_ssl._SSLContext._set_alpn_protocols - protos: Py_buffer - / -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLContext__set_alpn_protocols_impl(PySSLContext *self, - Py_buffer *protos) -/*[clinic end generated code: output=87599a7f76651a9b input=9bba964595d519be]*/ -{ -#if HAVE_ALPN - if ((size_t)protos->len > UINT_MAX) { - PyErr_Format(PyExc_OverflowError, - "protocols longer than %d bytes", UINT_MAX); - return NULL; - } - - PyMem_FREE(self->alpn_protocols); - self->alpn_protocols = PyMem_Malloc(protos->len); - if (!self->alpn_protocols) - return PyErr_NoMemory(); - memcpy(self->alpn_protocols, protos->buf, protos->len); - self->alpn_protocols_len = protos->len; - - if (SSL_CTX_set_alpn_protos(self->ctx, self->alpn_protocols, self->alpn_protocols_len)) - return PyErr_NoMemory(); - SSL_CTX_set_alpn_select_cb(self->ctx, _selectALPN_cb, self); - - Py_RETURN_NONE; -#else - PyErr_SetString(PyExc_NotImplementedError, - "The ALPN extension requires OpenSSL 1.0.2 or later."); - return NULL; -#endif -} - -static PyObject * -get_verify_mode(PySSLContext *self, void *c) -{ - /* ignore SSL_VERIFY_CLIENT_ONCE and SSL_VERIFY_POST_HANDSHAKE */ - int mask = (SSL_VERIFY_NONE | SSL_VERIFY_PEER | - SSL_VERIFY_FAIL_IF_NO_PEER_CERT); - switch (SSL_CTX_get_verify_mode(self->ctx) & mask) { - case SSL_VERIFY_NONE: - return PyLong_FromLong(PY_SSL_CERT_NONE); - case SSL_VERIFY_PEER: - return PyLong_FromLong(PY_SSL_CERT_OPTIONAL); - case SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT: - return PyLong_FromLong(PY_SSL_CERT_REQUIRED); - } - PyErr_SetString(PySSLErrorObject, - "invalid return value from SSL_CTX_get_verify_mode"); - return NULL; -} - -static int -set_verify_mode(PySSLContext *self, PyObject *arg, void *c) -{ - int n; - if (!PyArg_Parse(arg, "i", &n)) - return -1; - if (n == PY_SSL_CERT_NONE && self->check_hostname) { - PyErr_SetString(PyExc_ValueError, - "Cannot set verify_mode to CERT_NONE when " - "check_hostname is enabled."); - return -1; - } - return _set_verify_mode(self, n); -} - -static PyObject * -get_verify_flags(PySSLContext *self, void *c) -{ - X509_STORE *store; - X509_VERIFY_PARAM *param; - unsigned long flags; - - store = SSL_CTX_get_cert_store(self->ctx); - param = X509_STORE_get0_param(store); - flags = X509_VERIFY_PARAM_get_flags(param); - return PyLong_FromUnsignedLong(flags); -} - -static int -set_verify_flags(PySSLContext *self, PyObject *arg, void *c) -{ - X509_STORE *store; - X509_VERIFY_PARAM *param; - unsigned long new_flags, flags, set, clear; - - if (!PyArg_Parse(arg, "k", &new_flags)) - return -1; - store = SSL_CTX_get_cert_store(self->ctx); - param = X509_STORE_get0_param(store); - flags = X509_VERIFY_PARAM_get_flags(param); - clear = flags & ~new_flags; - set = ~flags & new_flags; - if (clear) { - if (!X509_VERIFY_PARAM_clear_flags(param, clear)) { - _setSSLError(NULL, 0, __FILE__, __LINE__); - return -1; - } - } - if (set) { - if (!X509_VERIFY_PARAM_set_flags(param, set)) { - _setSSLError(NULL, 0, __FILE__, __LINE__); - return -1; - } - } - return 0; -} - -static PyObject * -get_options(PySSLContext *self, void *c) -{ - return PyLong_FromLong(SSL_CTX_get_options(self->ctx)); -} - -static int -set_options(PySSLContext *self, PyObject *arg, void *c) -{ - long new_opts, opts, set, clear; - if (!PyArg_Parse(arg, "l", &new_opts)) - return -1; - opts = SSL_CTX_get_options(self->ctx); - clear = opts & ~new_opts; - set = ~opts & new_opts; - if (clear) { -#ifdef HAVE_SSL_CTX_CLEAR_OPTIONS - SSL_CTX_clear_options(self->ctx, clear); -#else - PyErr_SetString(PyExc_ValueError, - "can't clear options before OpenSSL 0.9.8m"); - return -1; -#endif - } - if (set) - SSL_CTX_set_options(self->ctx, set); - return 0; -} - -static PyObject * -get_check_hostname(PySSLContext *self, void *c) -{ - return PyBool_FromLong(self->check_hostname); -} - -static int -set_check_hostname(PySSLContext *self, PyObject *arg, void *c) -{ - int check_hostname; - if (!PyArg_Parse(arg, "p", &check_hostname)) - return -1; - if (check_hostname && - SSL_CTX_get_verify_mode(self->ctx) == SSL_VERIFY_NONE) { - PyErr_SetString(PyExc_ValueError, - "check_hostname needs a SSL context with either " - "CERT_OPTIONAL or CERT_REQUIRED"); - return -1; - } - self->check_hostname = check_hostname; - return 0; -} - -static PyObject * -get_post_handshake_auth(PySSLContext *self, void *c) { -#if TLS1_3_VERSION - return PyBool_FromLong(self->post_handshake_auth); -#else - Py_RETURN_NONE; -#endif -} - -#if TLS1_3_VERSION -static int -set_post_handshake_auth(PySSLContext *self, PyObject *arg, void *c) { - int (*verify_cb)(int, X509_STORE_CTX *) = NULL; - int mode = SSL_CTX_get_verify_mode(self->ctx); - int pha = PyObject_IsTrue(arg); - - if (pha == -1) { - return -1; - } - self->post_handshake_auth = pha; - - /* client-side socket setting, ignored by server-side */ - SSL_CTX_set_post_handshake_auth(self->ctx, pha); - - /* server-side socket setting, ignored by client-side */ - verify_cb = SSL_CTX_get_verify_callback(self->ctx); - if (pha) { - mode |= SSL_VERIFY_POST_HANDSHAKE; - } else { - mode ^= SSL_VERIFY_POST_HANDSHAKE; - } - SSL_CTX_set_verify(self->ctx, mode, verify_cb); - - return 0; -} -#endif - -typedef struct { - PyThreadState *thread_state; - PyObject *callable; - char *password; - int size; - int error; -} _PySSLPasswordInfo; - -static int -_pwinfo_set(_PySSLPasswordInfo *pw_info, PyObject* password, - const char *bad_type_error) -{ - /* Set the password and size fields of a _PySSLPasswordInfo struct - from a unicode, bytes, or byte array object. - The password field will be dynamically allocated and must be freed - by the caller */ - PyObject *password_bytes = NULL; - const char *data = NULL; - Py_ssize_t size; - - if (PyUnicode_Check(password)) { - password_bytes = PyUnicode_AsEncodedString(password, NULL, NULL); - if (!password_bytes) { - goto error; - } - data = PyBytes_AS_STRING(password_bytes); - size = PyBytes_GET_SIZE(password_bytes); - } else if (PyBytes_Check(password)) { - data = PyBytes_AS_STRING(password); - size = PyBytes_GET_SIZE(password); - } else if (PyByteArray_Check(password)) { - data = PyByteArray_AS_STRING(password); - size = PyByteArray_GET_SIZE(password); - } else { - PyErr_SetString(PyExc_TypeError, bad_type_error); - goto error; - } - - if (size > (Py_ssize_t)INT_MAX) { - PyErr_Format(PyExc_ValueError, - "password cannot be longer than %d bytes", INT_MAX); - goto error; - } - - PyMem_Free(pw_info->password); - pw_info->password = PyMem_Malloc(size); - if (!pw_info->password) { - PyErr_SetString(PyExc_MemoryError, - "unable to allocate password buffer"); - goto error; - } - memcpy(pw_info->password, data, size); - pw_info->size = (int)size; - - Py_XDECREF(password_bytes); - return 1; - -error: - Py_XDECREF(password_bytes); - return 0; -} - -static int -_password_callback(char *buf, int size, int rwflag, void *userdata) -{ - _PySSLPasswordInfo *pw_info = (_PySSLPasswordInfo*) userdata; - PyObject *fn_ret = NULL; - - PySSL_END_ALLOW_THREADS_S(pw_info->thread_state); - - if (pw_info->callable) { - fn_ret = PyObject_CallFunctionObjArgs(pw_info->callable, NULL); - if (!fn_ret) { - /* TODO: It would be nice to move _ctypes_add_traceback() into the - core python API, so we could use it to add a frame here */ - goto error; - } - - if (!_pwinfo_set(pw_info, fn_ret, - "password callback must return a string")) { - goto error; - } - Py_CLEAR(fn_ret); - } - - if (pw_info->size > size) { - PyErr_Format(PyExc_ValueError, - "password cannot be longer than %d bytes", size); - goto error; - } - - PySSL_BEGIN_ALLOW_THREADS_S(pw_info->thread_state); - memcpy(buf, pw_info->password, pw_info->size); - return pw_info->size; - -error: - Py_XDECREF(fn_ret); - PySSL_BEGIN_ALLOW_THREADS_S(pw_info->thread_state); - pw_info->error = 1; - return -1; -} - -/*[clinic input] -_ssl._SSLContext.load_cert_chain - certfile: object - keyfile: object = NULL - password: object = NULL - -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLContext_load_cert_chain_impl(PySSLContext *self, PyObject *certfile, - PyObject *keyfile, PyObject *password) -/*[clinic end generated code: output=9480bc1c380e2095 input=7cf9ac673cbee6fc]*/ -{ - PyObject *certfile_bytes = NULL, *keyfile_bytes = NULL; - pem_password_cb *orig_passwd_cb = SSL_CTX_get_default_passwd_cb(self->ctx); - void *orig_passwd_userdata = SSL_CTX_get_default_passwd_cb_userdata(self->ctx); - _PySSLPasswordInfo pw_info = { NULL, NULL, NULL, 0, 0 }; - int r; - - errno = 0; - ERR_clear_error(); - if (keyfile == Py_None) - keyfile = NULL; - if (!PyUnicode_FSConverter(certfile, &certfile_bytes)) { - PyErr_SetString(PyExc_TypeError, - "certfile should be a valid filesystem path"); - return NULL; - } - if (keyfile && !PyUnicode_FSConverter(keyfile, &keyfile_bytes)) { - PyErr_SetString(PyExc_TypeError, - "keyfile should be a valid filesystem path"); - goto error; - } - if (password && password != Py_None) { - if (PyCallable_Check(password)) { - pw_info.callable = password; - } else if (!_pwinfo_set(&pw_info, password, - "password should be a string or callable")) { - goto error; - } - SSL_CTX_set_default_passwd_cb(self->ctx, _password_callback); - SSL_CTX_set_default_passwd_cb_userdata(self->ctx, &pw_info); - } - PySSL_BEGIN_ALLOW_THREADS_S(pw_info.thread_state); - r = SSL_CTX_use_certificate_chain_file(self->ctx, - PyBytes_AS_STRING(certfile_bytes)); - PySSL_END_ALLOW_THREADS_S(pw_info.thread_state); - if (r != 1) { - if (pw_info.error) { - ERR_clear_error(); - /* the password callback has already set the error information */ - } - else if (errno != 0) { - ERR_clear_error(); - PyErr_SetFromErrno(PyExc_IOError); - } - else { - _setSSLError(NULL, 0, __FILE__, __LINE__); - } - goto error; - } - PySSL_BEGIN_ALLOW_THREADS_S(pw_info.thread_state); - r = SSL_CTX_use_PrivateKey_file(self->ctx, - PyBytes_AS_STRING(keyfile ? keyfile_bytes : certfile_bytes), - SSL_FILETYPE_PEM); - PySSL_END_ALLOW_THREADS_S(pw_info.thread_state); - Py_CLEAR(keyfile_bytes); - Py_CLEAR(certfile_bytes); - if (r != 1) { - if (pw_info.error) { - ERR_clear_error(); - /* the password callback has already set the error information */ - } - else if (errno != 0) { - ERR_clear_error(); - PyErr_SetFromErrno(PyExc_IOError); - } - else { - _setSSLError(NULL, 0, __FILE__, __LINE__); - } - goto error; - } - PySSL_BEGIN_ALLOW_THREADS_S(pw_info.thread_state); - r = SSL_CTX_check_private_key(self->ctx); - PySSL_END_ALLOW_THREADS_S(pw_info.thread_state); - if (r != 1) { - _setSSLError(NULL, 0, __FILE__, __LINE__); - goto error; - } - SSL_CTX_set_default_passwd_cb(self->ctx, orig_passwd_cb); - SSL_CTX_set_default_passwd_cb_userdata(self->ctx, orig_passwd_userdata); - PyMem_Free(pw_info.password); - Py_RETURN_NONE; - -error: - SSL_CTX_set_default_passwd_cb(self->ctx, orig_passwd_cb); - SSL_CTX_set_default_passwd_cb_userdata(self->ctx, orig_passwd_userdata); - PyMem_Free(pw_info.password); - Py_XDECREF(keyfile_bytes); - Py_XDECREF(certfile_bytes); - return NULL; -} - -/* internal helper function, returns -1 on error - */ -static int -_add_ca_certs(PySSLContext *self, void *data, Py_ssize_t len, - int filetype) -{ - BIO *biobuf = NULL; - X509_STORE *store; - int retval = 0, err, loaded = 0; - - assert(filetype == SSL_FILETYPE_ASN1 || filetype == SSL_FILETYPE_PEM); - - if (len <= 0) { - PyErr_SetString(PyExc_ValueError, - "Empty certificate data"); - return -1; - } else if (len > INT_MAX) { - PyErr_SetString(PyExc_OverflowError, - "Certificate data is too long."); - return -1; - } - - biobuf = BIO_new_mem_buf(data, (int)len); - if (biobuf == NULL) { - _setSSLError("Can't allocate buffer", 0, __FILE__, __LINE__); - return -1; - } - - store = SSL_CTX_get_cert_store(self->ctx); - assert(store != NULL); - - while (1) { - X509 *cert = NULL; - int r; - - if (filetype == SSL_FILETYPE_ASN1) { - cert = d2i_X509_bio(biobuf, NULL); - } else { - cert = PEM_read_bio_X509(biobuf, NULL, - SSL_CTX_get_default_passwd_cb(self->ctx), - SSL_CTX_get_default_passwd_cb_userdata(self->ctx) - ); - } - if (cert == NULL) { - break; - } - r = X509_STORE_add_cert(store, cert); - X509_free(cert); - if (!r) { - err = ERR_peek_last_error(); - if ((ERR_GET_LIB(err) == ERR_LIB_X509) && - (ERR_GET_REASON(err) == X509_R_CERT_ALREADY_IN_HASH_TABLE)) { - /* cert already in hash table, not an error */ - ERR_clear_error(); - } else { - break; - } - } - loaded++; - } - - err = ERR_peek_last_error(); - if ((filetype == SSL_FILETYPE_ASN1) && - (loaded > 0) && - (ERR_GET_LIB(err) == ERR_LIB_ASN1) && - (ERR_GET_REASON(err) == ASN1_R_HEADER_TOO_LONG)) { - /* EOF ASN1 file, not an error */ - ERR_clear_error(); - retval = 0; - } else if ((filetype == SSL_FILETYPE_PEM) && - (loaded > 0) && - (ERR_GET_LIB(err) == ERR_LIB_PEM) && - (ERR_GET_REASON(err) == PEM_R_NO_START_LINE)) { - /* EOF PEM file, not an error */ - ERR_clear_error(); - retval = 0; - } else { - _setSSLError(NULL, 0, __FILE__, __LINE__); - retval = -1; - } - - BIO_free(biobuf); - return retval; -} - - -/*[clinic input] -_ssl._SSLContext.load_verify_locations - cafile: object = NULL - capath: object = NULL - cadata: object = NULL - -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLContext_load_verify_locations_impl(PySSLContext *self, - PyObject *cafile, - PyObject *capath, - PyObject *cadata) -/*[clinic end generated code: output=454c7e41230ca551 input=997f1fb3a784ef88]*/ -{ - PyObject *cafile_bytes = NULL, *capath_bytes = NULL; - const char *cafile_buf = NULL, *capath_buf = NULL; - int r = 0, ok = 1; - - errno = 0; - if (cafile == Py_None) - cafile = NULL; - if (capath == Py_None) - capath = NULL; - if (cadata == Py_None) - cadata = NULL; - - if (cafile == NULL && capath == NULL && cadata == NULL) { - PyErr_SetString(PyExc_TypeError, - "cafile, capath and cadata cannot be all omitted"); - goto error; - } - if (cafile && !PyUnicode_FSConverter(cafile, &cafile_bytes)) { - PyErr_SetString(PyExc_TypeError, - "cafile should be a valid filesystem path"); - goto error; - } - if (capath && !PyUnicode_FSConverter(capath, &capath_bytes)) { - PyErr_SetString(PyExc_TypeError, - "capath should be a valid filesystem path"); - goto error; - } - - /* validata cadata type and load cadata */ - if (cadata) { - Py_buffer buf; - PyObject *cadata_ascii = NULL; - - if (PyObject_GetBuffer(cadata, &buf, PyBUF_SIMPLE) == 0) { - if (!PyBuffer_IsContiguous(&buf, 'C') || buf.ndim > 1) { - PyBuffer_Release(&buf); - PyErr_SetString(PyExc_TypeError, - "cadata should be a contiguous buffer with " - "a single dimension"); - goto error; - } - r = _add_ca_certs(self, buf.buf, buf.len, SSL_FILETYPE_ASN1); - PyBuffer_Release(&buf); - if (r == -1) { - goto error; - } - } else { - PyErr_Clear(); - cadata_ascii = PyUnicode_AsASCIIString(cadata); - if (cadata_ascii == NULL) { - PyErr_SetString(PyExc_TypeError, - "cadata should be an ASCII string or a " - "bytes-like object"); - goto error; - } - r = _add_ca_certs(self, - PyBytes_AS_STRING(cadata_ascii), - PyBytes_GET_SIZE(cadata_ascii), - SSL_FILETYPE_PEM); - Py_DECREF(cadata_ascii); - if (r == -1) { - goto error; - } - } - } - - /* load cafile or capath */ - if (cafile || capath) { - if (cafile) - cafile_buf = PyBytes_AS_STRING(cafile_bytes); - if (capath) - capath_buf = PyBytes_AS_STRING(capath_bytes); - PySSL_BEGIN_ALLOW_THREADS - r = SSL_CTX_load_verify_locations(self->ctx, cafile_buf, capath_buf); - PySSL_END_ALLOW_THREADS - if (r != 1) { - ok = 0; - if (errno != 0) { - ERR_clear_error(); - PyErr_SetFromErrno(PyExc_IOError); - } - else { - _setSSLError(NULL, 0, __FILE__, __LINE__); - } - goto error; - } - } - goto end; - - error: - ok = 0; - end: - Py_XDECREF(cafile_bytes); - Py_XDECREF(capath_bytes); - if (ok) { - Py_RETURN_NONE; - } else { - return NULL; - } -} - -/*[clinic input] -_ssl._SSLContext.load_dh_params - path as filepath: object - / - -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLContext_load_dh_params(PySSLContext *self, PyObject *filepath) -/*[clinic end generated code: output=1c8e57a38e055af0 input=c8871f3c796ae1d6]*/ -{ - FILE *f; - DH *dh; - - f = _Py_fopen_obj(filepath, "rb"); - if (f == NULL) - return NULL; - - errno = 0; - PySSL_BEGIN_ALLOW_THREADS - dh = PEM_read_DHparams(f, NULL, NULL, NULL); - fclose(f); - PySSL_END_ALLOW_THREADS - if (dh == NULL) { - if (errno != 0) { - ERR_clear_error(); - PyErr_SetFromErrnoWithFilenameObject(PyExc_OSError, filepath); - } - else { - _setSSLError(NULL, 0, __FILE__, __LINE__); - } - return NULL; - } - if (SSL_CTX_set_tmp_dh(self->ctx, dh) == 0) - _setSSLError(NULL, 0, __FILE__, __LINE__); - DH_free(dh); - Py_RETURN_NONE; -} - -/*[clinic input] -_ssl._SSLContext._wrap_socket - sock: object(subclass_of="PySocketModule.Sock_Type") - server_side: int - server_hostname as hostname_obj: object = None - -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLContext__wrap_socket_impl(PySSLContext *self, PyObject *sock, - int server_side, PyObject *hostname_obj) -/*[clinic end generated code: output=6973e4b60995e933 input=83859b9156ddfc63]*/ -{ - char *hostname = NULL; - PyObject *res; - - /* server_hostname is either None (or absent), or to be encoded - using the idna encoding. */ - if (hostname_obj != Py_None) { - if (!PyArg_Parse(hostname_obj, "et", "idna", &hostname)) - return NULL; - } - - res = (PyObject *) newPySSLSocket(self, (PySocketSockObject *)sock, - server_side, hostname, - NULL, NULL); - if (hostname != NULL) - PyMem_Free(hostname); - return res; -} - -/*[clinic input] -_ssl._SSLContext._wrap_bio - incoming: object(subclass_of="&PySSLMemoryBIO_Type", type="PySSLMemoryBIO *") - outgoing: object(subclass_of="&PySSLMemoryBIO_Type", type="PySSLMemoryBIO *") - server_side: int - server_hostname as hostname_obj: object = None - -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLContext__wrap_bio_impl(PySSLContext *self, PySSLMemoryBIO *incoming, - PySSLMemoryBIO *outgoing, int server_side, - PyObject *hostname_obj) -/*[clinic end generated code: output=4fe4ba75ad95940d input=17725ecdac0bf220]*/ -{ - char *hostname = NULL; - PyObject *res; - - /* server_hostname is either None (or absent), or to be encoded - using the idna encoding. */ - if (hostname_obj != Py_None) { - if (!PyArg_Parse(hostname_obj, "et", "idna", &hostname)) - return NULL; - } - - res = (PyObject *) newPySSLSocket(self, NULL, server_side, hostname, - incoming, outgoing); - - PyMem_Free(hostname); - return res; -} - -/*[clinic input] -_ssl._SSLContext.session_stats -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLContext_session_stats_impl(PySSLContext *self) -/*[clinic end generated code: output=0d96411c42893bfb input=7e0a81fb11102c8b]*/ -{ - int r; - PyObject *value, *stats = PyDict_New(); - if (!stats) - return NULL; - -#define ADD_STATS(SSL_NAME, KEY_NAME) \ - value = PyLong_FromLong(SSL_CTX_sess_ ## SSL_NAME (self->ctx)); \ - if (value == NULL) \ - goto error; \ - r = PyDict_SetItemString(stats, KEY_NAME, value); \ - Py_DECREF(value); \ - if (r < 0) \ - goto error; - - ADD_STATS(number, "number"); - ADD_STATS(connect, "connect"); - ADD_STATS(connect_good, "connect_good"); - ADD_STATS(connect_renegotiate, "connect_renegotiate"); - ADD_STATS(accept, "accept"); - ADD_STATS(accept_good, "accept_good"); - ADD_STATS(accept_renegotiate, "accept_renegotiate"); - ADD_STATS(accept, "accept"); - ADD_STATS(hits, "hits"); - ADD_STATS(misses, "misses"); - ADD_STATS(timeouts, "timeouts"); - ADD_STATS(cache_full, "cache_full"); - -#undef ADD_STATS - - return stats; - -error: - Py_DECREF(stats); - return NULL; -} - -/*[clinic input] -_ssl._SSLContext.set_default_verify_paths -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLContext_set_default_verify_paths_impl(PySSLContext *self) -/*[clinic end generated code: output=0bee74e6e09deaaa input=35f3408021463d74]*/ -{ - if (!SSL_CTX_set_default_verify_paths(self->ctx)) { - _setSSLError(NULL, 0, __FILE__, __LINE__); - return NULL; - } - Py_RETURN_NONE; -} - -#ifndef OPENSSL_NO_ECDH -/*[clinic input] -_ssl._SSLContext.set_ecdh_curve - name: object - / - -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLContext_set_ecdh_curve(PySSLContext *self, PyObject *name) -/*[clinic end generated code: output=23022c196e40d7d2 input=c2bafb6f6e34726b]*/ -{ - PyObject *name_bytes; - int nid; - EC_KEY *key; - - if (!PyUnicode_FSConverter(name, &name_bytes)) - return NULL; - assert(PyBytes_Check(name_bytes)); - nid = OBJ_sn2nid(PyBytes_AS_STRING(name_bytes)); - Py_DECREF(name_bytes); - if (nid == 0) { - PyErr_Format(PyExc_ValueError, - "unknown elliptic curve name %R", name); - return NULL; - } - key = EC_KEY_new_by_curve_name(nid); - if (key == NULL) { - _setSSLError(NULL, 0, __FILE__, __LINE__); - return NULL; - } - SSL_CTX_set_tmp_ecdh(self->ctx, key); - EC_KEY_free(key); - Py_RETURN_NONE; -} -#endif - -#if HAVE_SNI && !defined(OPENSSL_NO_TLSEXT) -static int -_servername_callback(SSL *s, int *al, void *args) -{ - int ret; - PySSLContext *ssl_ctx = (PySSLContext *) args; - PySSLSocket *ssl; - PyObject *servername_o; - PyObject *servername_idna; - PyObject *result; - /* The high-level ssl.SSLSocket object */ - PyObject *ssl_socket; - const char *servername = SSL_get_servername(s, TLSEXT_NAMETYPE_host_name); -#ifdef WITH_THREAD - PyGILState_STATE gstate = PyGILState_Ensure(); -#endif - - if (ssl_ctx->set_hostname == NULL) { - /* remove race condition in this the call back while if removing the - * callback is in progress */ -#ifdef WITH_THREAD - PyGILState_Release(gstate); -#endif - return SSL_TLSEXT_ERR_OK; - } - - ssl = SSL_get_app_data(s); - assert(PySSLSocket_Check(ssl)); - - /* The servername callback expects an argument that represents the current - * SSL connection and that has a .context attribute that can be changed to - * identify the requested hostname. Since the official API is the Python - * level API we want to pass the callback a Python level object rather than - * a _ssl.SSLSocket instance. If there's an "owner" (typically an - * SSLObject) that will be passed. Otherwise if there's a socket then that - * will be passed. If both do not exist only then the C-level object is - * passed. */ - if (ssl->owner) - ssl_socket = PyWeakref_GetObject(ssl->owner); - else if (ssl->Socket) - ssl_socket = PyWeakref_GetObject(ssl->Socket); - else - ssl_socket = (PyObject *) ssl; - - Py_INCREF(ssl_socket); - if (ssl_socket == Py_None) - goto error; - - if (servername == NULL) { - result = PyObject_CallFunctionObjArgs(ssl_ctx->set_hostname, ssl_socket, - Py_None, ssl_ctx, NULL); - } - else { - servername_o = PyBytes_FromString(servername); - if (servername_o == NULL) { - PyErr_WriteUnraisable((PyObject *) ssl_ctx); - goto error; - } - servername_idna = PyUnicode_FromEncodedObject(servername_o, "idna", NULL); - if (servername_idna == NULL) { - PyErr_WriteUnraisable(servername_o); - Py_DECREF(servername_o); - goto error; - } - Py_DECREF(servername_o); - result = PyObject_CallFunctionObjArgs(ssl_ctx->set_hostname, ssl_socket, - servername_idna, ssl_ctx, NULL); - Py_DECREF(servername_idna); - } - Py_DECREF(ssl_socket); - - if (result == NULL) { - PyErr_WriteUnraisable(ssl_ctx->set_hostname); - *al = SSL_AD_HANDSHAKE_FAILURE; - ret = SSL_TLSEXT_ERR_ALERT_FATAL; - } - else { - if (result != Py_None) { - *al = (int) PyLong_AsLong(result); - if (PyErr_Occurred()) { - PyErr_WriteUnraisable(result); - *al = SSL_AD_INTERNAL_ERROR; - } - ret = SSL_TLSEXT_ERR_ALERT_FATAL; - } - else { - ret = SSL_TLSEXT_ERR_OK; - } - Py_DECREF(result); - } - -#ifdef WITH_THREAD - PyGILState_Release(gstate); -#endif - return ret; - -error: - Py_DECREF(ssl_socket); - *al = SSL_AD_INTERNAL_ERROR; - ret = SSL_TLSEXT_ERR_ALERT_FATAL; -#ifdef WITH_THREAD - PyGILState_Release(gstate); -#endif - return ret; -} -#endif - -/*[clinic input] -_ssl._SSLContext.set_servername_callback - method as cb: object - / - -Set a callback that will be called when a server name is provided by the SSL/TLS client in the SNI extension. - -If the argument is None then the callback is disabled. The method is called -with the SSLSocket, the server name as a string, and the SSLContext object. -See RFC 6066 for details of the SNI extension. -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLContext_set_servername_callback(PySSLContext *self, PyObject *cb) -/*[clinic end generated code: output=3439a1b2d5d3b7ea input=a2a83620197d602b]*/ -{ -#if HAVE_SNI && !defined(OPENSSL_NO_TLSEXT) - Py_CLEAR(self->set_hostname); - if (cb == Py_None) { - SSL_CTX_set_tlsext_servername_callback(self->ctx, NULL); - } - else { - if (!PyCallable_Check(cb)) { - SSL_CTX_set_tlsext_servername_callback(self->ctx, NULL); - PyErr_SetString(PyExc_TypeError, - "not a callable object"); - return NULL; - } - Py_INCREF(cb); - self->set_hostname = cb; - SSL_CTX_set_tlsext_servername_callback(self->ctx, _servername_callback); - SSL_CTX_set_tlsext_servername_arg(self->ctx, self); - } - Py_RETURN_NONE; -#else - PyErr_SetString(PyExc_NotImplementedError, - "The TLS extension servername callback, " - "SSL_CTX_set_tlsext_servername_callback, " - "is not in the current OpenSSL library."); - return NULL; -#endif -} - -/*[clinic input] -_ssl._SSLContext.cert_store_stats - -Returns quantities of loaded X.509 certificates. - -X.509 certificates with a CA extension and certificate revocation lists -inside the context's cert store. - -NOTE: Certificates in a capath directory aren't loaded unless they have -been used at least once. -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLContext_cert_store_stats_impl(PySSLContext *self) -/*[clinic end generated code: output=5f356f4d9cca874d input=eb40dd0f6d0e40cf]*/ -{ - X509_STORE *store; - STACK_OF(X509_OBJECT) *objs; - X509_OBJECT *obj; - int x509 = 0, crl = 0, ca = 0, i; - - store = SSL_CTX_get_cert_store(self->ctx); - objs = X509_STORE_get0_objects(store); - for (i = 0; i < sk_X509_OBJECT_num(objs); i++) { - obj = sk_X509_OBJECT_value(objs, i); - switch (X509_OBJECT_get_type(obj)) { - case X509_LU_X509: - x509++; - if (X509_check_ca(X509_OBJECT_get0_X509(obj))) { - ca++; - } - break; - case X509_LU_CRL: - crl++; - break; - default: - /* Ignore X509_LU_FAIL, X509_LU_RETRY, X509_LU_PKEY. - * As far as I can tell they are internal states and never - * stored in a cert store */ - break; - } - } - return Py_BuildValue("{sisisi}", "x509", x509, "crl", crl, - "x509_ca", ca); -} - -/*[clinic input] -_ssl._SSLContext.get_ca_certs - binary_form: bool = False - -Returns a list of dicts with information of loaded CA certs. - -If the optional argument is True, returns a DER-encoded copy of the CA -certificate. - -NOTE: Certificates in a capath directory aren't loaded unless they have -been used at least once. -[clinic start generated code]*/ - -static PyObject * -_ssl__SSLContext_get_ca_certs_impl(PySSLContext *self, int binary_form) -/*[clinic end generated code: output=0d58f148f37e2938 input=6887b5a09b7f9076]*/ -{ - X509_STORE *store; - STACK_OF(X509_OBJECT) *objs; - PyObject *ci = NULL, *rlist = NULL; - int i; - - if ((rlist = PyList_New(0)) == NULL) { - return NULL; - } - - store = SSL_CTX_get_cert_store(self->ctx); - objs = X509_STORE_get0_objects(store); - for (i = 0; i < sk_X509_OBJECT_num(objs); i++) { - X509_OBJECT *obj; - X509 *cert; - - obj = sk_X509_OBJECT_value(objs, i); - if (X509_OBJECT_get_type(obj) != X509_LU_X509) { - /* not a x509 cert */ - continue; - } - /* CA for any purpose */ - cert = X509_OBJECT_get0_X509(obj); - if (!X509_check_ca(cert)) { - continue; - } - if (binary_form) { - ci = _certificate_to_der(cert); - } else { - ci = _decode_certificate(cert); - } - if (ci == NULL) { - goto error; - } - if (PyList_Append(rlist, ci) == -1) { - goto error; - } - Py_CLEAR(ci); - } - return rlist; - - error: - Py_XDECREF(ci); - Py_XDECREF(rlist); - return NULL; -} - - -static PyGetSetDef context_getsetlist[] = { - {"check_hostname", (getter) get_check_hostname, - (setter) set_check_hostname, NULL}, - {"options", (getter) get_options, - (setter) set_options, NULL}, - {"post_handshake_auth", (getter) get_post_handshake_auth, -#ifdef TLS1_3_VERSION - (setter) set_post_handshake_auth, -#else - NULL, -#endif - NULL}, - {"verify_flags", (getter) get_verify_flags, - (setter) set_verify_flags, NULL}, - {"verify_mode", (getter) get_verify_mode, - (setter) set_verify_mode, NULL}, - {NULL}, /* sentinel */ -}; - -static struct PyMethodDef context_methods[] = { - _SSL__SSLCONTEXT__WRAP_SOCKET_METHODDEF - _SSL__SSLCONTEXT__WRAP_BIO_METHODDEF - _SSL__SSLCONTEXT_SET_CIPHERS_METHODDEF - _SSL__SSLCONTEXT__SET_ALPN_PROTOCOLS_METHODDEF - _SSL__SSLCONTEXT__SET_NPN_PROTOCOLS_METHODDEF - _SSL__SSLCONTEXT_LOAD_CERT_CHAIN_METHODDEF - _SSL__SSLCONTEXT_LOAD_DH_PARAMS_METHODDEF - _SSL__SSLCONTEXT_LOAD_VERIFY_LOCATIONS_METHODDEF - _SSL__SSLCONTEXT_SESSION_STATS_METHODDEF - _SSL__SSLCONTEXT_SET_DEFAULT_VERIFY_PATHS_METHODDEF - _SSL__SSLCONTEXT_SET_ECDH_CURVE_METHODDEF - _SSL__SSLCONTEXT_SET_SERVERNAME_CALLBACK_METHODDEF - _SSL__SSLCONTEXT_CERT_STORE_STATS_METHODDEF - _SSL__SSLCONTEXT_GET_CA_CERTS_METHODDEF - _SSL__SSLCONTEXT_GET_CIPHERS_METHODDEF - {NULL, NULL} /* sentinel */ -}; - -static PyTypeObject PySSLContext_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ssl._SSLContext", /*tp_name*/ - sizeof(PySSLContext), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - (destructor)context_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_reserved*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - (traverseproc) context_traverse, /*tp_traverse*/ - (inquiry) context_clear, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - context_methods, /*tp_methods*/ - 0, /*tp_members*/ - context_getsetlist, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - _ssl__SSLContext, /*tp_new*/ -}; - - -/* - * MemoryBIO objects - */ - -/*[clinic input] -@classmethod -_ssl.MemoryBIO.__new__ - -[clinic start generated code]*/ - -static PyObject * -_ssl_MemoryBIO_impl(PyTypeObject *type) -/*[clinic end generated code: output=8820a58db78330ac input=26d22e4909ecb1b5]*/ -{ - BIO *bio; - PySSLMemoryBIO *self; - - bio = BIO_new(BIO_s_mem()); - if (bio == NULL) { - PyErr_SetString(PySSLErrorObject, - "failed to allocate BIO"); - return NULL; - } - /* Since our BIO is non-blocking an empty read() does not indicate EOF, - * just that no data is currently available. The SSL routines should retry - * the read, which we can achieve by calling BIO_set_retry_read(). */ - BIO_set_retry_read(bio); - BIO_set_mem_eof_return(bio, -1); - - assert(type != NULL && type->tp_alloc != NULL); - self = (PySSLMemoryBIO *) type->tp_alloc(type, 0); - if (self == NULL) { - BIO_free(bio); - return NULL; - } - self->bio = bio; - self->eof_written = 0; - - return (PyObject *) self; -} - -static void -memory_bio_dealloc(PySSLMemoryBIO *self) -{ - BIO_free(self->bio); - Py_TYPE(self)->tp_free(self); -} - -static PyObject * -memory_bio_get_pending(PySSLMemoryBIO *self, void *c) -{ - return PyLong_FromLong(BIO_ctrl_pending(self->bio)); -} - -PyDoc_STRVAR(PySSL_memory_bio_pending_doc, -"The number of bytes pending in the memory BIO."); - -static PyObject * -memory_bio_get_eof(PySSLMemoryBIO *self, void *c) -{ - return PyBool_FromLong((BIO_ctrl_pending(self->bio) == 0) - && self->eof_written); -} - -PyDoc_STRVAR(PySSL_memory_bio_eof_doc, -"Whether the memory BIO is at EOF."); - -/*[clinic input] -_ssl.MemoryBIO.read - size as len: int = -1 - / - -Read up to size bytes from the memory BIO. - -If size is not specified, read the entire buffer. -If the return value is an empty bytes instance, this means either -EOF or that no data is available. Use the "eof" property to -distinguish between the two. -[clinic start generated code]*/ - -static PyObject * -_ssl_MemoryBIO_read_impl(PySSLMemoryBIO *self, int len) -/*[clinic end generated code: output=a657aa1e79cd01b3 input=574d7be06a902366]*/ -{ - int avail, nbytes; - PyObject *result; - - avail = BIO_ctrl_pending(self->bio); - if ((len < 0) || (len > avail)) - len = avail; - - result = PyBytes_FromStringAndSize(NULL, len); - if ((result == NULL) || (len == 0)) - return result; - - nbytes = BIO_read(self->bio, PyBytes_AS_STRING(result), len); - if (nbytes < 0) { - Py_DECREF(result); - _setSSLError(NULL, 0, __FILE__, __LINE__); - return NULL; - } - - /* There should never be any short reads but check anyway. */ - if (nbytes < len) { - _PyBytes_Resize(&result, nbytes); - } - - return result; -} - -/*[clinic input] -_ssl.MemoryBIO.write - b: Py_buffer - / - -Writes the bytes b into the memory BIO. - -Returns the number of bytes written. -[clinic start generated code]*/ - -static PyObject * -_ssl_MemoryBIO_write_impl(PySSLMemoryBIO *self, Py_buffer *b) -/*[clinic end generated code: output=156ec59110d75935 input=e45757b3e17c4808]*/ -{ - int nbytes; - - if (b->len > INT_MAX) { - PyErr_Format(PyExc_OverflowError, - "string longer than %d bytes", INT_MAX); - return NULL; - } - - if (self->eof_written) { - PyErr_SetString(PySSLErrorObject, - "cannot write() after write_eof()"); - return NULL; - } - - nbytes = BIO_write(self->bio, b->buf, b->len); - if (nbytes < 0) { - _setSSLError(NULL, 0, __FILE__, __LINE__); - return NULL; - } - - return PyLong_FromLong(nbytes); -} - -/*[clinic input] -_ssl.MemoryBIO.write_eof - -Write an EOF marker to the memory BIO. - -When all data has been read, the "eof" property will be True. -[clinic start generated code]*/ - -static PyObject * -_ssl_MemoryBIO_write_eof_impl(PySSLMemoryBIO *self) -/*[clinic end generated code: output=d4106276ccd1ed34 input=56a945f1d29e8bd6]*/ -{ - self->eof_written = 1; - /* After an EOF is written, a zero return from read() should be a real EOF - * i.e. it should not be retried. Clear the SHOULD_RETRY flag. */ - BIO_clear_retry_flags(self->bio); - BIO_set_mem_eof_return(self->bio, 0); - - Py_RETURN_NONE; -} - -static PyGetSetDef memory_bio_getsetlist[] = { - {"pending", (getter) memory_bio_get_pending, NULL, - PySSL_memory_bio_pending_doc}, - {"eof", (getter) memory_bio_get_eof, NULL, - PySSL_memory_bio_eof_doc}, - {NULL}, /* sentinel */ -}; - -static struct PyMethodDef memory_bio_methods[] = { - _SSL_MEMORYBIO_READ_METHODDEF - _SSL_MEMORYBIO_WRITE_METHODDEF - _SSL_MEMORYBIO_WRITE_EOF_METHODDEF - {NULL, NULL} /* sentinel */ -}; - -static PyTypeObject PySSLMemoryBIO_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ssl.MemoryBIO", /*tp_name*/ - sizeof(PySSLMemoryBIO), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - (destructor)memory_bio_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_reserved*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT, /*tp_flags*/ - 0, /*tp_doc*/ - 0, /*tp_traverse*/ - 0, /*tp_clear*/ - 0, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - memory_bio_methods, /*tp_methods*/ - 0, /*tp_members*/ - memory_bio_getsetlist, /*tp_getset*/ - 0, /*tp_base*/ - 0, /*tp_dict*/ - 0, /*tp_descr_get*/ - 0, /*tp_descr_set*/ - 0, /*tp_dictoffset*/ - 0, /*tp_init*/ - 0, /*tp_alloc*/ - _ssl_MemoryBIO, /*tp_new*/ -}; - - -/* - * SSL Session object - */ - -static void -PySSLSession_dealloc(PySSLSession *self) -{ - /* bpo-31095: UnTrack is needed before calling any callbacks */ - PyObject_GC_UnTrack(self); - Py_XDECREF(self->ctx); - if (self->session != NULL) { - SSL_SESSION_free(self->session); - } - PyObject_GC_Del(self); -} - -static PyObject * -PySSLSession_richcompare(PyObject *left, PyObject *right, int op) -{ - int result; - - if (left == NULL || right == NULL) { - PyErr_BadInternalCall(); - return NULL; - } - - if (!PySSLSession_Check(left) || !PySSLSession_Check(right)) { - Py_RETURN_NOTIMPLEMENTED; - } - - if (left == right) { - result = 0; - } else { - const unsigned char *left_id, *right_id; - unsigned int left_len, right_len; - left_id = SSL_SESSION_get_id(((PySSLSession *)left)->session, - &left_len); - right_id = SSL_SESSION_get_id(((PySSLSession *)right)->session, - &right_len); - if (left_len == right_len) { - result = memcmp(left_id, right_id, left_len); - } else { - result = 1; - } - } - - switch (op) { - case Py_EQ: - if (result == 0) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } - break; - case Py_NE: - if (result != 0) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } - break; - case Py_LT: - case Py_LE: - case Py_GT: - case Py_GE: - Py_RETURN_NOTIMPLEMENTED; - break; - default: - PyErr_BadArgument(); - return NULL; - } -} - -static int -PySSLSession_traverse(PySSLSession *self, visitproc visit, void *arg) -{ - Py_VISIT(self->ctx); - return 0; -} - -static int -PySSLSession_clear(PySSLSession *self) -{ - Py_CLEAR(self->ctx); - return 0; -} - - -static PyObject * -PySSLSession_get_time(PySSLSession *self, void *closure) { - return PyLong_FromLong(SSL_SESSION_get_time(self->session)); -} - -PyDoc_STRVAR(PySSLSession_get_time_doc, -"Session creation time (seconds since epoch)."); - - -static PyObject * -PySSLSession_get_timeout(PySSLSession *self, void *closure) { - return PyLong_FromLong(SSL_SESSION_get_timeout(self->session)); -} - -PyDoc_STRVAR(PySSLSession_get_timeout_doc, -"Session timeout (delta in seconds)."); - - -static PyObject * -PySSLSession_get_ticket_lifetime_hint(PySSLSession *self, void *closure) { - unsigned long hint = SSL_SESSION_get_ticket_lifetime_hint(self->session); - return PyLong_FromUnsignedLong(hint); -} - -PyDoc_STRVAR(PySSLSession_get_ticket_lifetime_hint_doc, -"Ticket life time hint."); - - -static PyObject * -PySSLSession_get_session_id(PySSLSession *self, void *closure) { - const unsigned char *id; - unsigned int len; - id = SSL_SESSION_get_id(self->session, &len); - return PyBytes_FromStringAndSize((const char *)id, len); -} - -PyDoc_STRVAR(PySSLSession_get_session_id_doc, -"Session id"); - - -static PyObject * -PySSLSession_get_has_ticket(PySSLSession *self, void *closure) { - if (SSL_SESSION_has_ticket(self->session)) { - Py_RETURN_TRUE; - } else { - Py_RETURN_FALSE; - } -} - -PyDoc_STRVAR(PySSLSession_get_has_ticket_doc, -"Does the session contain a ticket?"); - - -static PyGetSetDef PySSLSession_getsetlist[] = { - {"has_ticket", (getter) PySSLSession_get_has_ticket, NULL, - PySSLSession_get_has_ticket_doc}, - {"id", (getter) PySSLSession_get_session_id, NULL, - PySSLSession_get_session_id_doc}, - {"ticket_lifetime_hint", (getter) PySSLSession_get_ticket_lifetime_hint, - NULL, PySSLSession_get_ticket_lifetime_hint_doc}, - {"time", (getter) PySSLSession_get_time, NULL, - PySSLSession_get_time_doc}, - {"timeout", (getter) PySSLSession_get_timeout, NULL, - PySSLSession_get_timeout_doc}, - {NULL}, /* sentinel */ -}; - -static PyTypeObject PySSLSession_Type = { - PyVarObject_HEAD_INIT(NULL, 0) - "_ssl.Session", /*tp_name*/ - sizeof(PySSLSession), /*tp_basicsize*/ - 0, /*tp_itemsize*/ - (destructor)PySSLSession_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_reserved*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash*/ - 0, /*tp_call*/ - 0, /*tp_str*/ - 0, /*tp_getattro*/ - 0, /*tp_setattro*/ - 0, /*tp_as_buffer*/ - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ - 0, /*tp_doc*/ - (traverseproc)PySSLSession_traverse, /*tp_traverse*/ - (inquiry)PySSLSession_clear, /*tp_clear*/ - PySSLSession_richcompare, /*tp_richcompare*/ - 0, /*tp_weaklistoffset*/ - 0, /*tp_iter*/ - 0, /*tp_iternext*/ - 0, /*tp_methods*/ - 0, /*tp_members*/ - PySSLSession_getsetlist, /*tp_getset*/ -}; - - -/* helper routines for seeding the SSL PRNG */ -/*[clinic input] -_ssl.RAND_add - string as view: Py_buffer(accept={str, buffer}) - entropy: double - / - -Mix string into the OpenSSL PRNG state. - -entropy (a float) is a lower bound on the entropy contained in -string. See RFC 4086. -[clinic start generated code]*/ - -static PyObject * -_ssl_RAND_add_impl(PyObject *module, Py_buffer *view, double entropy) -/*[clinic end generated code: output=e6dd48df9c9024e9 input=5c33017422828f5c]*/ -{ - const char *buf; - Py_ssize_t len, written; - - buf = (const char *)view->buf; - len = view->len; - do { - written = Py_MIN(len, INT_MAX); - RAND_add(buf, (int)written, entropy); - buf += written; - len -= written; - } while (len); - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject * -PySSL_RAND(int len, int pseudo) -{ - int ok; - PyObject *bytes; - unsigned long err; - const char *errstr; - PyObject *v; - - if (len < 0) { - PyErr_SetString(PyExc_ValueError, "num must be positive"); - return NULL; - } - - bytes = PyBytes_FromStringAndSize(NULL, len); - if (bytes == NULL) - return NULL; - if (pseudo) { - ok = RAND_pseudo_bytes((unsigned char*)PyBytes_AS_STRING(bytes), len); - if (ok == 0 || ok == 1) - return Py_BuildValue("NO", bytes, ok == 1 ? Py_True : Py_False); - } - else { - ok = RAND_bytes((unsigned char*)PyBytes_AS_STRING(bytes), len); - if (ok == 1) - return bytes; - } - Py_DECREF(bytes); - - err = ERR_get_error(); - errstr = ERR_reason_error_string(err); - v = Py_BuildValue("(ks)", err, errstr); - if (v != NULL) { - PyErr_SetObject(PySSLErrorObject, v); - Py_DECREF(v); - } - return NULL; -} - -/*[clinic input] -_ssl.RAND_bytes - n: int - / - -Generate n cryptographically strong pseudo-random bytes. -[clinic start generated code]*/ - -static PyObject * -_ssl_RAND_bytes_impl(PyObject *module, int n) -/*[clinic end generated code: output=977da635e4838bc7 input=678ddf2872dfebfc]*/ -{ - return PySSL_RAND(n, 0); -} - -/*[clinic input] -_ssl.RAND_pseudo_bytes - n: int - / - -Generate n pseudo-random bytes. - -Return a pair (bytes, is_cryptographic). is_cryptographic is True -if the bytes generated are cryptographically strong. -[clinic start generated code]*/ - -static PyObject * -_ssl_RAND_pseudo_bytes_impl(PyObject *module, int n) -/*[clinic end generated code: output=b1509e937000e52d input=58312bd53f9bbdd0]*/ -{ - return PySSL_RAND(n, 1); -} - -/*[clinic input] -_ssl.RAND_status - -Returns 1 if the OpenSSL PRNG has been seeded with enough data and 0 if not. - -It is necessary to seed the PRNG with RAND_add() on some platforms before -using the ssl() function. -[clinic start generated code]*/ - -static PyObject * -_ssl_RAND_status_impl(PyObject *module) -/*[clinic end generated code: output=7e0aaa2d39fdc1ad input=8a774b02d1dc81f3]*/ -{ - return PyLong_FromLong(RAND_status()); -} - -#ifndef OPENSSL_NO_EGD -/* LCOV_EXCL_START */ -/*[clinic input] -_ssl.RAND_egd - path: object(converter="PyUnicode_FSConverter") - / - -Queries the entropy gather daemon (EGD) on the socket named by 'path'. - -Returns number of bytes read. Raises SSLError if connection to EGD -fails or if it does not provide enough data to seed PRNG. -[clinic start generated code]*/ - -static PyObject * -_ssl_RAND_egd_impl(PyObject *module, PyObject *path) -/*[clinic end generated code: output=02a67c7c367f52fa input=1aeb7eb948312195]*/ -{ - int bytes = RAND_egd(PyBytes_AsString(path)); - Py_DECREF(path); - if (bytes == -1) { - PyErr_SetString(PySSLErrorObject, - "EGD connection failed or EGD did not return " - "enough data to seed the PRNG"); - return NULL; - } - return PyLong_FromLong(bytes); -} -/* LCOV_EXCL_STOP */ -#endif /* OPENSSL_NO_EGD */ - - - -/*[clinic input] -_ssl.get_default_verify_paths - -Return search paths and environment vars that are used by SSLContext's set_default_verify_paths() to load default CAs. - -The values are 'cert_file_env', 'cert_file', 'cert_dir_env', 'cert_dir'. -[clinic start generated code]*/ - -static PyObject * -_ssl_get_default_verify_paths_impl(PyObject *module) -/*[clinic end generated code: output=e5b62a466271928b input=5210c953d98c3eb5]*/ -{ - PyObject *ofile_env = NULL; - PyObject *ofile = NULL; - PyObject *odir_env = NULL; - PyObject *odir = NULL; - -#define CONVERT(info, target) { \ - const char *tmp = (info); \ - target = NULL; \ - if (!tmp) { Py_INCREF(Py_None); target = Py_None; } \ - else if ((target = PyUnicode_DecodeFSDefault(tmp)) == NULL) { \ - target = PyBytes_FromString(tmp); } \ - if (!target) goto error; \ - } - - CONVERT(X509_get_default_cert_file_env(), ofile_env); - CONVERT(X509_get_default_cert_file(), ofile); - CONVERT(X509_get_default_cert_dir_env(), odir_env); - CONVERT(X509_get_default_cert_dir(), odir); -#undef CONVERT - - return Py_BuildValue("NNNN", ofile_env, ofile, odir_env, odir); - - error: - Py_XDECREF(ofile_env); - Py_XDECREF(ofile); - Py_XDECREF(odir_env); - Py_XDECREF(odir); - return NULL; -} - -static PyObject* -asn1obj2py(ASN1_OBJECT *obj) -{ - int nid; - const char *ln, *sn; - - nid = OBJ_obj2nid(obj); - if (nid == NID_undef) { - PyErr_Format(PyExc_ValueError, "Unknown object"); - return NULL; - } - sn = OBJ_nid2sn(nid); - ln = OBJ_nid2ln(nid); - return Py_BuildValue("issN", nid, sn, ln, _asn1obj2py(obj, 1)); -} - -/*[clinic input] -_ssl.txt2obj - txt: str - name: bool = False - -Lookup NID, short name, long name and OID of an ASN1_OBJECT. - -By default objects are looked up by OID. With name=True short and -long name are also matched. -[clinic start generated code]*/ - -static PyObject * -_ssl_txt2obj_impl(PyObject *module, const char *txt, int name) -/*[clinic end generated code: output=c38e3991347079c1 input=1c1e7d0aa7c48602]*/ -{ - PyObject *result = NULL; - ASN1_OBJECT *obj; - - obj = OBJ_txt2obj(txt, name ? 0 : 1); - if (obj == NULL) { - PyErr_Format(PyExc_ValueError, "unknown object '%.100s'", txt); - return NULL; - } - result = asn1obj2py(obj); - ASN1_OBJECT_free(obj); - return result; -} - -/*[clinic input] -_ssl.nid2obj - nid: int - / - -Lookup NID, short name, long name and OID of an ASN1_OBJECT by NID. -[clinic start generated code]*/ - -static PyObject * -_ssl_nid2obj_impl(PyObject *module, int nid) -/*[clinic end generated code: output=4a98ab691cd4f84a input=51787a3bee7d8f98]*/ -{ - PyObject *result = NULL; - ASN1_OBJECT *obj; - - if (nid < NID_undef) { - PyErr_SetString(PyExc_ValueError, "NID must be positive."); - return NULL; - } - obj = OBJ_nid2obj(nid); - if (obj == NULL) { - PyErr_Format(PyExc_ValueError, "unknown NID %i", nid); - return NULL; - } - result = asn1obj2py(obj); - ASN1_OBJECT_free(obj); - return result; -} - -#ifdef _MSC_VER - -static PyObject* -certEncodingType(DWORD encodingType) -{ - static PyObject *x509_asn = NULL; - static PyObject *pkcs_7_asn = NULL; - - if (x509_asn == NULL) { - x509_asn = PyUnicode_InternFromString("x509_asn"); - if (x509_asn == NULL) - return NULL; - } - if (pkcs_7_asn == NULL) { - pkcs_7_asn = PyUnicode_InternFromString("pkcs_7_asn"); - if (pkcs_7_asn == NULL) - return NULL; - } - switch(encodingType) { - case X509_ASN_ENCODING: - Py_INCREF(x509_asn); - return x509_asn; - case PKCS_7_ASN_ENCODING: - Py_INCREF(pkcs_7_asn); - return pkcs_7_asn; - default: - return PyLong_FromLong(encodingType); - } -} - -static PyObject* -parseKeyUsage(PCCERT_CONTEXT pCertCtx, DWORD flags) -{ - CERT_ENHKEY_USAGE *usage; - DWORD size, error, i; - PyObject *retval; - - if (!CertGetEnhancedKeyUsage(pCertCtx, flags, NULL, &size)) { - error = GetLastError(); - if (error == CRYPT_E_NOT_FOUND) { - Py_RETURN_TRUE; - } - return PyErr_SetFromWindowsErr(error); - } - - usage = (CERT_ENHKEY_USAGE*)PyMem_Malloc(size); - if (usage == NULL) { - return PyErr_NoMemory(); - } - - /* Now get the actual enhanced usage property */ - if (!CertGetEnhancedKeyUsage(pCertCtx, flags, usage, &size)) { - PyMem_Free(usage); - error = GetLastError(); - if (error == CRYPT_E_NOT_FOUND) { - Py_RETURN_TRUE; - } - return PyErr_SetFromWindowsErr(error); - } - retval = PySet_New(NULL); - if (retval == NULL) { - goto error; - } - for (i = 0; i < usage->cUsageIdentifier; ++i) { - if (usage->rgpszUsageIdentifier[i]) { - PyObject *oid; - int err; - oid = PyUnicode_FromString(usage->rgpszUsageIdentifier[i]); - if (oid == NULL) { - Py_CLEAR(retval); - goto error; - } - err = PySet_Add(retval, oid); - Py_DECREF(oid); - if (err == -1) { - Py_CLEAR(retval); - goto error; - } - } - } - error: - PyMem_Free(usage); - return retval; -} - -/*[clinic input] -_ssl.enum_certificates - store_name: str - -Retrieve certificates from Windows' cert store. - -store_name may be one of 'CA', 'ROOT' or 'MY'. The system may provide -more cert storages, too. The function returns a list of (bytes, -encoding_type, trust) tuples. The encoding_type flag can be interpreted -with X509_ASN_ENCODING or PKCS_7_ASN_ENCODING. The trust setting is either -a set of OIDs or the boolean True. -[clinic start generated code]*/ - -static PyObject * -_ssl_enum_certificates_impl(PyObject *module, const char *store_name) -/*[clinic end generated code: output=5134dc8bb3a3c893 input=915f60d70461ea4e]*/ -{ - HCERTSTORE hStore = NULL; - PCCERT_CONTEXT pCertCtx = NULL; - PyObject *keyusage = NULL, *cert = NULL, *enc = NULL, *tup = NULL; - PyObject *result = NULL; - - result = PyList_New(0); - if (result == NULL) { - return NULL; - } - hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM_A, 0, (HCRYPTPROV)NULL, - CERT_STORE_READONLY_FLAG | CERT_SYSTEM_STORE_LOCAL_MACHINE, - store_name); - if (hStore == NULL) { - Py_DECREF(result); - return PyErr_SetFromWindowsErr(GetLastError()); - } - - while (pCertCtx = CertEnumCertificatesInStore(hStore, pCertCtx)) { - cert = PyBytes_FromStringAndSize((const char*)pCertCtx->pbCertEncoded, - pCertCtx->cbCertEncoded); - if (!cert) { - Py_CLEAR(result); - break; - } - if ((enc = certEncodingType(pCertCtx->dwCertEncodingType)) == NULL) { - Py_CLEAR(result); - break; - } - keyusage = parseKeyUsage(pCertCtx, CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG); - if (keyusage == Py_True) { - Py_DECREF(keyusage); - keyusage = parseKeyUsage(pCertCtx, CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG); - } - if (keyusage == NULL) { - Py_CLEAR(result); - break; - } - if ((tup = PyTuple_New(3)) == NULL) { - Py_CLEAR(result); - break; - } - PyTuple_SET_ITEM(tup, 0, cert); - cert = NULL; - PyTuple_SET_ITEM(tup, 1, enc); - enc = NULL; - PyTuple_SET_ITEM(tup, 2, keyusage); - keyusage = NULL; - if (PyList_Append(result, tup) < 0) { - Py_CLEAR(result); - break; - } - Py_CLEAR(tup); - } - if (pCertCtx) { - /* loop ended with an error, need to clean up context manually */ - CertFreeCertificateContext(pCertCtx); - } - - /* In error cases cert, enc and tup may not be NULL */ - Py_XDECREF(cert); - Py_XDECREF(enc); - Py_XDECREF(keyusage); - Py_XDECREF(tup); - - if (!CertCloseStore(hStore, 0)) { - /* This error case might shadow another exception.*/ - Py_XDECREF(result); - return PyErr_SetFromWindowsErr(GetLastError()); - } - return result; -} - -/*[clinic input] -_ssl.enum_crls - store_name: str - -Retrieve CRLs from Windows' cert store. - -store_name may be one of 'CA', 'ROOT' or 'MY'. The system may provide -more cert storages, too. The function returns a list of (bytes, -encoding_type) tuples. The encoding_type flag can be interpreted with -X509_ASN_ENCODING or PKCS_7_ASN_ENCODING. -[clinic start generated code]*/ - -static PyObject * -_ssl_enum_crls_impl(PyObject *module, const char *store_name) -/*[clinic end generated code: output=bce467f60ccd03b6 input=a1f1d7629f1c5d3d]*/ -{ - HCERTSTORE hStore = NULL; - PCCRL_CONTEXT pCrlCtx = NULL; - PyObject *crl = NULL, *enc = NULL, *tup = NULL; - PyObject *result = NULL; - - result = PyList_New(0); - if (result == NULL) { - return NULL; - } - hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM_A, 0, (HCRYPTPROV)NULL, - CERT_STORE_READONLY_FLAG | CERT_SYSTEM_STORE_LOCAL_MACHINE, - store_name); - if (hStore == NULL) { - Py_DECREF(result); - return PyErr_SetFromWindowsErr(GetLastError()); - } - - while (pCrlCtx = CertEnumCRLsInStore(hStore, pCrlCtx)) { - crl = PyBytes_FromStringAndSize((const char*)pCrlCtx->pbCrlEncoded, - pCrlCtx->cbCrlEncoded); - if (!crl) { - Py_CLEAR(result); - break; - } - if ((enc = certEncodingType(pCrlCtx->dwCertEncodingType)) == NULL) { - Py_CLEAR(result); - break; - } - if ((tup = PyTuple_New(2)) == NULL) { - Py_CLEAR(result); - break; - } - PyTuple_SET_ITEM(tup, 0, crl); - crl = NULL; - PyTuple_SET_ITEM(tup, 1, enc); - enc = NULL; - - if (PyList_Append(result, tup) < 0) { - Py_CLEAR(result); - break; - } - Py_CLEAR(tup); - } - if (pCrlCtx) { - /* loop ended with an error, need to clean up context manually */ - CertFreeCRLContext(pCrlCtx); - } - - /* In error cases cert, enc and tup may not be NULL */ - Py_XDECREF(crl); - Py_XDECREF(enc); - Py_XDECREF(tup); - - if (!CertCloseStore(hStore, 0)) { - /* This error case might shadow another exception.*/ - Py_XDECREF(result); - return PyErr_SetFromWindowsErr(GetLastError()); - } - return result; -} - -#endif /* _MSC_VER */ - -/* List of functions exported by this module. */ -static PyMethodDef PySSL_methods[] = { - _SSL__TEST_DECODE_CERT_METHODDEF - _SSL_RAND_ADD_METHODDEF - _SSL_RAND_BYTES_METHODDEF - _SSL_RAND_PSEUDO_BYTES_METHODDEF - _SSL_RAND_EGD_METHODDEF - _SSL_RAND_STATUS_METHODDEF - _SSL_GET_DEFAULT_VERIFY_PATHS_METHODDEF - _SSL_ENUM_CERTIFICATES_METHODDEF - _SSL_ENUM_CRLS_METHODDEF - _SSL_TXT2OBJ_METHODDEF - _SSL_NID2OBJ_METHODDEF - {NULL, NULL} /* Sentinel */ -}; - - -#ifdef HAVE_OPENSSL_CRYPTO_LOCK - -/* an implementation of OpenSSL threading operations in terms - * of the Python C thread library - * Only used up to 1.0.2. OpenSSL 1.1.0+ has its own locking code. - */ - -static PyThread_type_lock *_ssl_locks = NULL; - -#if OPENSSL_VERSION_NUMBER >= 0x10000000 -/* use new CRYPTO_THREADID API. */ -static void -_ssl_threadid_callback(CRYPTO_THREADID *id) -{ - CRYPTO_THREADID_set_numeric(id, - (unsigned long)PyThread_get_thread_ident()); -} -#else -/* deprecated CRYPTO_set_id_callback() API. */ -static unsigned long -_ssl_thread_id_function (void) { - return PyThread_get_thread_ident(); -} -#endif - -static void _ssl_thread_locking_function - (int mode, int n, const char *file, int line) { - /* this function is needed to perform locking on shared data - structures. (Note that OpenSSL uses a number of global data - structures that will be implicitly shared whenever multiple - threads use OpenSSL.) Multi-threaded applications will - crash at random if it is not set. - - locking_function() must be able to handle up to - CRYPTO_num_locks() different mutex locks. It sets the n-th - lock if mode & CRYPTO_LOCK, and releases it otherwise. - - file and line are the file number of the function setting the - lock. They can be useful for debugging. - */ - - if ((_ssl_locks == NULL) || - (n < 0) || ((unsigned)n >= _ssl_locks_count)) - return; - - if (mode & CRYPTO_LOCK) { - PyThread_acquire_lock(_ssl_locks[n], 1); - } else { - PyThread_release_lock(_ssl_locks[n]); - } -} - -static int _setup_ssl_threads(void) { - - unsigned int i; - - if (_ssl_locks == NULL) { - _ssl_locks_count = CRYPTO_num_locks(); - _ssl_locks = PyMem_Calloc(_ssl_locks_count, - sizeof(PyThread_type_lock)); - if (_ssl_locks == NULL) { - PyErr_NoMemory(); - return 0; - } - for (i = 0; i < _ssl_locks_count; i++) { - _ssl_locks[i] = PyThread_allocate_lock(); - if (_ssl_locks[i] == NULL) { - unsigned int j; - for (j = 0; j < i; j++) { - PyThread_free_lock(_ssl_locks[j]); - } - PyMem_Free(_ssl_locks); - return 0; - } - } - CRYPTO_set_locking_callback(_ssl_thread_locking_function); -#if OPENSSL_VERSION_NUMBER >= 0x10000000 - CRYPTO_THREADID_set_callback(_ssl_threadid_callback); -#else - CRYPTO_set_id_callback(_ssl_thread_id_function); -#endif - } - return 1; -} - -#endif /* HAVE_OPENSSL_CRYPTO_LOCK for WITH_THREAD && OpenSSL < 1.1.0 */ - -PyDoc_STRVAR(module_doc, -"Implementation module for SSL socket operations. See the socket module\n\ -for documentation."); - - -static struct PyModuleDef _sslmodule = { - PyModuleDef_HEAD_INIT, - "_ssl", - module_doc, - -1, - PySSL_methods, - NULL, - NULL, - NULL, - NULL -}; - - -static void -parse_openssl_version(unsigned long libver, - unsigned int *major, unsigned int *minor, - unsigned int *fix, unsigned int *patch, - unsigned int *status) -{ - *status = libver & 0xF; - libver >>= 4; - *patch = libver & 0xFF; - libver >>= 8; - *fix = libver & 0xFF; - libver >>= 8; - *minor = libver & 0xFF; - libver >>= 8; - *major = libver & 0xFF; -} - -PyMODINIT_FUNC -PyInit__ssl(void) -{ - PyObject *m, *d, *r; - unsigned long libver; - unsigned int major, minor, fix, patch, status; - PySocketModule_APIObject *socket_api; - struct py_ssl_error_code *errcode; - struct py_ssl_library_code *libcode; - - if (PyType_Ready(&PySSLContext_Type) < 0) - return NULL; - if (PyType_Ready(&PySSLSocket_Type) < 0) - return NULL; - if (PyType_Ready(&PySSLMemoryBIO_Type) < 0) - return NULL; - if (PyType_Ready(&PySSLSession_Type) < 0) - return NULL; - - - m = PyModule_Create(&_sslmodule); - if (m == NULL) - return NULL; - d = PyModule_GetDict(m); - - /* Load _socket module and its C API */ - socket_api = PySocketModule_ImportModuleAndAPI(); - if (!socket_api) - return NULL; - PySocketModule = *socket_api; - -#ifndef OPENSSL_VERSION_1_1 - /* Load all algorithms and initialize cpuid */ - OPENSSL_add_all_algorithms_noconf(); - /* Init OpenSSL */ - SSL_load_error_strings(); - SSL_library_init(); -#endif - -#ifdef WITH_THREAD -#ifdef HAVE_OPENSSL_CRYPTO_LOCK - /* note that this will start threading if not already started */ - if (!_setup_ssl_threads()) { - return NULL; - } -#elif OPENSSL_VERSION_1_1 && defined(OPENSSL_THREADS) - /* OpenSSL 1.1.0 builtin thread support is enabled */ - _ssl_locks_count++; -#endif -#endif /* WITH_THREAD */ - - /* Add symbols to module dict */ - sslerror_type_slots[0].pfunc = PyExc_OSError; - PySSLErrorObject = PyType_FromSpec(&sslerror_type_spec); - if (PySSLErrorObject == NULL) - return NULL; - - PySSLZeroReturnErrorObject = PyErr_NewExceptionWithDoc( - "ssl.SSLZeroReturnError", SSLZeroReturnError_doc, - PySSLErrorObject, NULL); - PySSLWantReadErrorObject = PyErr_NewExceptionWithDoc( - "ssl.SSLWantReadError", SSLWantReadError_doc, - PySSLErrorObject, NULL); - PySSLWantWriteErrorObject = PyErr_NewExceptionWithDoc( - "ssl.SSLWantWriteError", SSLWantWriteError_doc, - PySSLErrorObject, NULL); - PySSLSyscallErrorObject = PyErr_NewExceptionWithDoc( - "ssl.SSLSyscallError", SSLSyscallError_doc, - PySSLErrorObject, NULL); - PySSLEOFErrorObject = PyErr_NewExceptionWithDoc( - "ssl.SSLEOFError", SSLEOFError_doc, - PySSLErrorObject, NULL); - if (PySSLZeroReturnErrorObject == NULL - || PySSLWantReadErrorObject == NULL - || PySSLWantWriteErrorObject == NULL - || PySSLSyscallErrorObject == NULL - || PySSLEOFErrorObject == NULL) - return NULL; - if (PyDict_SetItemString(d, "SSLError", PySSLErrorObject) != 0 - || PyDict_SetItemString(d, "SSLZeroReturnError", PySSLZeroReturnErrorObject) != 0 - || PyDict_SetItemString(d, "SSLWantReadError", PySSLWantReadErrorObject) != 0 - || PyDict_SetItemString(d, "SSLWantWriteError", PySSLWantWriteErrorObject) != 0 - || PyDict_SetItemString(d, "SSLSyscallError", PySSLSyscallErrorObject) != 0 - || PyDict_SetItemString(d, "SSLEOFError", PySSLEOFErrorObject) != 0) - return NULL; - if (PyDict_SetItemString(d, "_SSLContext", - (PyObject *)&PySSLContext_Type) != 0) - return NULL; - if (PyDict_SetItemString(d, "_SSLSocket", - (PyObject *)&PySSLSocket_Type) != 0) - return NULL; - if (PyDict_SetItemString(d, "MemoryBIO", - (PyObject *)&PySSLMemoryBIO_Type) != 0) - return NULL; - if (PyDict_SetItemString(d, "SSLSession", - (PyObject *)&PySSLSession_Type) != 0) - return NULL; - - PyModule_AddIntConstant(m, "SSL_ERROR_ZERO_RETURN", - PY_SSL_ERROR_ZERO_RETURN); - PyModule_AddIntConstant(m, "SSL_ERROR_WANT_READ", - PY_SSL_ERROR_WANT_READ); - PyModule_AddIntConstant(m, "SSL_ERROR_WANT_WRITE", - PY_SSL_ERROR_WANT_WRITE); - PyModule_AddIntConstant(m, "SSL_ERROR_WANT_X509_LOOKUP", - PY_SSL_ERROR_WANT_X509_LOOKUP); - PyModule_AddIntConstant(m, "SSL_ERROR_SYSCALL", - PY_SSL_ERROR_SYSCALL); - PyModule_AddIntConstant(m, "SSL_ERROR_SSL", - PY_SSL_ERROR_SSL); - PyModule_AddIntConstant(m, "SSL_ERROR_WANT_CONNECT", - PY_SSL_ERROR_WANT_CONNECT); - /* non ssl.h errorcodes */ - PyModule_AddIntConstant(m, "SSL_ERROR_EOF", - PY_SSL_ERROR_EOF); - PyModule_AddIntConstant(m, "SSL_ERROR_INVALID_ERROR_CODE", - PY_SSL_ERROR_INVALID_ERROR_CODE); - /* cert requirements */ - PyModule_AddIntConstant(m, "CERT_NONE", - PY_SSL_CERT_NONE); - PyModule_AddIntConstant(m, "CERT_OPTIONAL", - PY_SSL_CERT_OPTIONAL); - PyModule_AddIntConstant(m, "CERT_REQUIRED", - PY_SSL_CERT_REQUIRED); - /* CRL verification for verification_flags */ - PyModule_AddIntConstant(m, "VERIFY_DEFAULT", - 0); - PyModule_AddIntConstant(m, "VERIFY_CRL_CHECK_LEAF", - X509_V_FLAG_CRL_CHECK); - PyModule_AddIntConstant(m, "VERIFY_CRL_CHECK_CHAIN", - X509_V_FLAG_CRL_CHECK|X509_V_FLAG_CRL_CHECK_ALL); - PyModule_AddIntConstant(m, "VERIFY_X509_STRICT", - X509_V_FLAG_X509_STRICT); -#ifdef X509_V_FLAG_TRUSTED_FIRST - PyModule_AddIntConstant(m, "VERIFY_X509_TRUSTED_FIRST", - X509_V_FLAG_TRUSTED_FIRST); -#endif - - /* Alert Descriptions from ssl.h */ - /* note RESERVED constants no longer intended for use have been removed */ - /* http://www.iana.org/assignments/tls-parameters/tls-parameters.xml#tls-parameters-6 */ - -#define ADD_AD_CONSTANT(s) \ - PyModule_AddIntConstant(m, "ALERT_DESCRIPTION_"#s, \ - SSL_AD_##s) - - ADD_AD_CONSTANT(CLOSE_NOTIFY); - ADD_AD_CONSTANT(UNEXPECTED_MESSAGE); - ADD_AD_CONSTANT(BAD_RECORD_MAC); - ADD_AD_CONSTANT(RECORD_OVERFLOW); - ADD_AD_CONSTANT(DECOMPRESSION_FAILURE); - ADD_AD_CONSTANT(HANDSHAKE_FAILURE); - ADD_AD_CONSTANT(BAD_CERTIFICATE); - ADD_AD_CONSTANT(UNSUPPORTED_CERTIFICATE); - ADD_AD_CONSTANT(CERTIFICATE_REVOKED); - ADD_AD_CONSTANT(CERTIFICATE_EXPIRED); - ADD_AD_CONSTANT(CERTIFICATE_UNKNOWN); - ADD_AD_CONSTANT(ILLEGAL_PARAMETER); - ADD_AD_CONSTANT(UNKNOWN_CA); - ADD_AD_CONSTANT(ACCESS_DENIED); - ADD_AD_CONSTANT(DECODE_ERROR); - ADD_AD_CONSTANT(DECRYPT_ERROR); - ADD_AD_CONSTANT(PROTOCOL_VERSION); - ADD_AD_CONSTANT(INSUFFICIENT_SECURITY); - ADD_AD_CONSTANT(INTERNAL_ERROR); - ADD_AD_CONSTANT(USER_CANCELLED); - ADD_AD_CONSTANT(NO_RENEGOTIATION); - /* Not all constants are in old OpenSSL versions */ -#ifdef SSL_AD_UNSUPPORTED_EXTENSION - ADD_AD_CONSTANT(UNSUPPORTED_EXTENSION); -#endif -#ifdef SSL_AD_CERTIFICATE_UNOBTAINABLE - ADD_AD_CONSTANT(CERTIFICATE_UNOBTAINABLE); -#endif -#ifdef SSL_AD_UNRECOGNIZED_NAME - ADD_AD_CONSTANT(UNRECOGNIZED_NAME); -#endif -#ifdef SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE - ADD_AD_CONSTANT(BAD_CERTIFICATE_STATUS_RESPONSE); -#endif -#ifdef SSL_AD_BAD_CERTIFICATE_HASH_VALUE - ADD_AD_CONSTANT(BAD_CERTIFICATE_HASH_VALUE); -#endif -#ifdef SSL_AD_UNKNOWN_PSK_IDENTITY - ADD_AD_CONSTANT(UNKNOWN_PSK_IDENTITY); -#endif - -#undef ADD_AD_CONSTANT - - /* protocol versions */ -#ifndef OPENSSL_NO_SSL2 - PyModule_AddIntConstant(m, "PROTOCOL_SSLv2", - PY_SSL_VERSION_SSL2); -#endif -#ifndef OPENSSL_NO_SSL3 - PyModule_AddIntConstant(m, "PROTOCOL_SSLv3", - PY_SSL_VERSION_SSL3); -#endif - PyModule_AddIntConstant(m, "PROTOCOL_SSLv23", - PY_SSL_VERSION_TLS); - PyModule_AddIntConstant(m, "PROTOCOL_TLS", - PY_SSL_VERSION_TLS); - PyModule_AddIntConstant(m, "PROTOCOL_TLS_CLIENT", - PY_SSL_VERSION_TLS_CLIENT); - PyModule_AddIntConstant(m, "PROTOCOL_TLS_SERVER", - PY_SSL_VERSION_TLS_SERVER); - PyModule_AddIntConstant(m, "PROTOCOL_TLSv1", - PY_SSL_VERSION_TLS1); -#if HAVE_TLSv1_2 - PyModule_AddIntConstant(m, "PROTOCOL_TLSv1_1", - PY_SSL_VERSION_TLS1_1); - PyModule_AddIntConstant(m, "PROTOCOL_TLSv1_2", - PY_SSL_VERSION_TLS1_2); -#endif - - /* protocol options */ - PyModule_AddIntConstant(m, "OP_ALL", - SSL_OP_ALL & ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS); - PyModule_AddIntConstant(m, "OP_NO_SSLv2", SSL_OP_NO_SSLv2); - PyModule_AddIntConstant(m, "OP_NO_SSLv3", SSL_OP_NO_SSLv3); - PyModule_AddIntConstant(m, "OP_NO_TLSv1", SSL_OP_NO_TLSv1); -#if HAVE_TLSv1_2 - PyModule_AddIntConstant(m, "OP_NO_TLSv1_1", SSL_OP_NO_TLSv1_1); - PyModule_AddIntConstant(m, "OP_NO_TLSv1_2", SSL_OP_NO_TLSv1_2); -#endif -#ifdef SSL_OP_NO_TLSv1_3 - PyModule_AddIntConstant(m, "OP_NO_TLSv1_3", SSL_OP_NO_TLSv1_3); -#else - PyModule_AddIntConstant(m, "OP_NO_TLSv1_3", 0); -#endif - PyModule_AddIntConstant(m, "OP_CIPHER_SERVER_PREFERENCE", - SSL_OP_CIPHER_SERVER_PREFERENCE); - PyModule_AddIntConstant(m, "OP_SINGLE_DH_USE", SSL_OP_SINGLE_DH_USE); - PyModule_AddIntConstant(m, "OP_NO_TICKET", SSL_OP_NO_TICKET); -#ifdef SSL_OP_SINGLE_ECDH_USE - PyModule_AddIntConstant(m, "OP_SINGLE_ECDH_USE", SSL_OP_SINGLE_ECDH_USE); -#endif -#ifdef SSL_OP_NO_COMPRESSION - PyModule_AddIntConstant(m, "OP_NO_COMPRESSION", - SSL_OP_NO_COMPRESSION); -#endif -#ifdef SSL_OP_ENABLE_MIDDLEBOX_COMPAT - PyModule_AddIntConstant(m, "OP_ENABLE_MIDDLEBOX_COMPAT", - SSL_OP_ENABLE_MIDDLEBOX_COMPAT); -#endif - -#if HAVE_SNI - r = Py_True; -#else - r = Py_False; -#endif - Py_INCREF(r); - PyModule_AddObject(m, "HAS_SNI", r); - - r = Py_True; - Py_INCREF(r); - PyModule_AddObject(m, "HAS_TLS_UNIQUE", r); - -#ifdef OPENSSL_NO_ECDH - r = Py_False; -#else - r = Py_True; -#endif - Py_INCREF(r); - PyModule_AddObject(m, "HAS_ECDH", r); - -#if HAVE_NPN - r = Py_True; -#else - r = Py_False; -#endif - Py_INCREF(r); - PyModule_AddObject(m, "HAS_NPN", r); - -#if HAVE_ALPN - r = Py_True; -#else - r = Py_False; -#endif - Py_INCREF(r); - PyModule_AddObject(m, "HAS_ALPN", r); - -#if defined(TLS1_3_VERSION) && !defined(OPENSSL_NO_TLS1_3) - r = Py_True; -#else - r = Py_False; -#endif - Py_INCREF(r); - PyModule_AddObject(m, "HAS_TLSv1_3", r); - - /* Mappings for error codes */ - err_codes_to_names = PyDict_New(); - err_names_to_codes = PyDict_New(); - if (err_codes_to_names == NULL || err_names_to_codes == NULL) - return NULL; - errcode = error_codes; - while (errcode->mnemonic != NULL) { - PyObject *mnemo, *key; - mnemo = PyUnicode_FromString(errcode->mnemonic); - key = Py_BuildValue("ii", errcode->library, errcode->reason); - if (mnemo == NULL || key == NULL) - return NULL; - if (PyDict_SetItem(err_codes_to_names, key, mnemo)) - return NULL; - if (PyDict_SetItem(err_names_to_codes, mnemo, key)) - return NULL; - Py_DECREF(key); - Py_DECREF(mnemo); - errcode++; - } - if (PyModule_AddObject(m, "err_codes_to_names", err_codes_to_names)) - return NULL; - if (PyModule_AddObject(m, "err_names_to_codes", err_names_to_codes)) - return NULL; - - lib_codes_to_names = PyDict_New(); - if (lib_codes_to_names == NULL) - return NULL; - libcode = library_codes; - while (libcode->library != NULL) { - PyObject *mnemo, *key; - key = PyLong_FromLong(libcode->code); - mnemo = PyUnicode_FromString(libcode->library); - if (key == NULL || mnemo == NULL) - return NULL; - if (PyDict_SetItem(lib_codes_to_names, key, mnemo)) - return NULL; - Py_DECREF(key); - Py_DECREF(mnemo); - libcode++; - } - if (PyModule_AddObject(m, "lib_codes_to_names", lib_codes_to_names)) - return NULL; - - /* OpenSSL version */ - /* SSLeay() gives us the version of the library linked against, - which could be different from the headers version. - */ - libver = SSLeay(); - r = PyLong_FromUnsignedLong(libver); - if (r == NULL) - return NULL; - if (PyModule_AddObject(m, "OPENSSL_VERSION_NUMBER", r)) - return NULL; - parse_openssl_version(libver, &major, &minor, &fix, &patch, &status); - r = Py_BuildValue("IIIII", major, minor, fix, patch, status); - if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION_INFO", r)) - return NULL; - r = PyUnicode_FromString(SSLeay_version(SSLEAY_VERSION)); - if (r == NULL || PyModule_AddObject(m, "OPENSSL_VERSION", r)) - return NULL; - - libver = OPENSSL_VERSION_NUMBER; - parse_openssl_version(libver, &major, &minor, &fix, &patch, &status); - r = Py_BuildValue("IIIII", major, minor, fix, patch, status); - if (r == NULL || PyModule_AddObject(m, "_OPENSSL_API_VERSION", r)) - return NULL; - - return m; -} diff --git a/third_party/python/Modules/_ssl_data.inc b/third_party/python/Modules/_ssl_data.inc index d72dfee06..836224d83 100644 --- a/third_party/python/Modules/_ssl_data.inc +++ b/third_party/python/Modules/_ssl_data.inc @@ -2,6 +2,10 @@ /* File generated by Tools/ssl/make_ssl_data.py */ /* Generated on 2015-01-17T20:33:43.377453 */ +#define ERR_LIB_PEM 1 +#define ERR_LIB_X509 2 +#define ERR_LIB_SSL 6 + static struct py_ssl_library_code library_codes[] = { {"PEM", ERR_LIB_PEM}, {"SSL", ERR_LIB_SSL}, @@ -10,1940 +14,6 @@ static struct py_ssl_library_code library_codes[] = { }; static struct py_ssl_error_code error_codes[] = { - #ifdef PEM_R_BAD_BASE64_DECODE - {"BAD_BASE64_DECODE", ERR_LIB_PEM, PEM_R_BAD_BASE64_DECODE}, - #else - {"BAD_BASE64_DECODE", ERR_LIB_PEM, 100}, - #endif - #ifdef PEM_R_BAD_DECRYPT - {"BAD_DECRYPT", ERR_LIB_PEM, PEM_R_BAD_DECRYPT}, - #else - {"BAD_DECRYPT", ERR_LIB_PEM, 101}, - #endif - #ifdef PEM_R_BAD_END_LINE - {"BAD_END_LINE", ERR_LIB_PEM, PEM_R_BAD_END_LINE}, - #else - {"BAD_END_LINE", ERR_LIB_PEM, 102}, - #endif - #ifdef PEM_R_BAD_IV_CHARS - {"BAD_IV_CHARS", ERR_LIB_PEM, PEM_R_BAD_IV_CHARS}, - #else - {"BAD_IV_CHARS", ERR_LIB_PEM, 103}, - #endif - #ifdef PEM_R_BAD_MAGIC_NUMBER - {"BAD_MAGIC_NUMBER", ERR_LIB_PEM, PEM_R_BAD_MAGIC_NUMBER}, - #else - {"BAD_MAGIC_NUMBER", ERR_LIB_PEM, 116}, - #endif - #ifdef PEM_R_BAD_PASSWORD_READ - {"BAD_PASSWORD_READ", ERR_LIB_PEM, PEM_R_BAD_PASSWORD_READ}, - #else - {"BAD_PASSWORD_READ", ERR_LIB_PEM, 104}, - #endif - #ifdef PEM_R_BAD_VERSION_NUMBER - {"BAD_VERSION_NUMBER", ERR_LIB_PEM, PEM_R_BAD_VERSION_NUMBER}, - #else - {"BAD_VERSION_NUMBER", ERR_LIB_PEM, 117}, - #endif - #ifdef PEM_R_BIO_WRITE_FAILURE - {"BIO_WRITE_FAILURE", ERR_LIB_PEM, PEM_R_BIO_WRITE_FAILURE}, - #else - {"BIO_WRITE_FAILURE", ERR_LIB_PEM, 118}, - #endif - #ifdef PEM_R_CIPHER_IS_NULL - {"CIPHER_IS_NULL", ERR_LIB_PEM, PEM_R_CIPHER_IS_NULL}, - #else - {"CIPHER_IS_NULL", ERR_LIB_PEM, 127}, - #endif - #ifdef PEM_R_ERROR_CONVERTING_PRIVATE_KEY - {"ERROR_CONVERTING_PRIVATE_KEY", ERR_LIB_PEM, PEM_R_ERROR_CONVERTING_PRIVATE_KEY}, - #else - {"ERROR_CONVERTING_PRIVATE_KEY", ERR_LIB_PEM, 115}, - #endif - #ifdef PEM_R_EXPECTING_PRIVATE_KEY_BLOB - {"EXPECTING_PRIVATE_KEY_BLOB", ERR_LIB_PEM, PEM_R_EXPECTING_PRIVATE_KEY_BLOB}, - #else - {"EXPECTING_PRIVATE_KEY_BLOB", ERR_LIB_PEM, 119}, - #endif - #ifdef PEM_R_EXPECTING_PUBLIC_KEY_BLOB - {"EXPECTING_PUBLIC_KEY_BLOB", ERR_LIB_PEM, PEM_R_EXPECTING_PUBLIC_KEY_BLOB}, - #else - {"EXPECTING_PUBLIC_KEY_BLOB", ERR_LIB_PEM, 120}, - #endif - #ifdef PEM_R_INCONSISTENT_HEADER - {"INCONSISTENT_HEADER", ERR_LIB_PEM, PEM_R_INCONSISTENT_HEADER}, - #else - {"INCONSISTENT_HEADER", ERR_LIB_PEM, 121}, - #endif - #ifdef PEM_R_KEYBLOB_HEADER_PARSE_ERROR - {"KEYBLOB_HEADER_PARSE_ERROR", ERR_LIB_PEM, PEM_R_KEYBLOB_HEADER_PARSE_ERROR}, - #else - {"KEYBLOB_HEADER_PARSE_ERROR", ERR_LIB_PEM, 122}, - #endif - #ifdef PEM_R_KEYBLOB_TOO_SHORT - {"KEYBLOB_TOO_SHORT", ERR_LIB_PEM, PEM_R_KEYBLOB_TOO_SHORT}, - #else - {"KEYBLOB_TOO_SHORT", ERR_LIB_PEM, 123}, - #endif - #ifdef PEM_R_NOT_DEK_INFO - {"NOT_DEK_INFO", ERR_LIB_PEM, PEM_R_NOT_DEK_INFO}, - #else - {"NOT_DEK_INFO", ERR_LIB_PEM, 105}, - #endif - #ifdef PEM_R_NOT_ENCRYPTED - {"NOT_ENCRYPTED", ERR_LIB_PEM, PEM_R_NOT_ENCRYPTED}, - #else - {"NOT_ENCRYPTED", ERR_LIB_PEM, 106}, - #endif - #ifdef PEM_R_NOT_PROC_TYPE - {"NOT_PROC_TYPE", ERR_LIB_PEM, PEM_R_NOT_PROC_TYPE}, - #else - {"NOT_PROC_TYPE", ERR_LIB_PEM, 107}, - #endif - #ifdef PEM_R_NO_START_LINE - {"NO_START_LINE", ERR_LIB_PEM, PEM_R_NO_START_LINE}, - #else - {"NO_START_LINE", ERR_LIB_PEM, 108}, - #endif - #ifdef PEM_R_PROBLEMS_GETTING_PASSWORD - {"PROBLEMS_GETTING_PASSWORD", ERR_LIB_PEM, PEM_R_PROBLEMS_GETTING_PASSWORD}, - #else - {"PROBLEMS_GETTING_PASSWORD", ERR_LIB_PEM, 109}, - #endif - #ifdef PEM_R_PUBLIC_KEY_NO_RSA - {"PUBLIC_KEY_NO_RSA", ERR_LIB_PEM, PEM_R_PUBLIC_KEY_NO_RSA}, - #else - {"PUBLIC_KEY_NO_RSA", ERR_LIB_PEM, 110}, - #endif - #ifdef PEM_R_PVK_DATA_TOO_SHORT - {"PVK_DATA_TOO_SHORT", ERR_LIB_PEM, PEM_R_PVK_DATA_TOO_SHORT}, - #else - {"PVK_DATA_TOO_SHORT", ERR_LIB_PEM, 124}, - #endif - #ifdef PEM_R_PVK_TOO_SHORT - {"PVK_TOO_SHORT", ERR_LIB_PEM, PEM_R_PVK_TOO_SHORT}, - #else - {"PVK_TOO_SHORT", ERR_LIB_PEM, 125}, - #endif - #ifdef PEM_R_READ_KEY - {"READ_KEY", ERR_LIB_PEM, PEM_R_READ_KEY}, - #else - {"READ_KEY", ERR_LIB_PEM, 111}, - #endif - #ifdef PEM_R_SHORT_HEADER - {"SHORT_HEADER", ERR_LIB_PEM, PEM_R_SHORT_HEADER}, - #else - {"SHORT_HEADER", ERR_LIB_PEM, 112}, - #endif - #ifdef PEM_R_UNSUPPORTED_CIPHER - {"UNSUPPORTED_CIPHER", ERR_LIB_PEM, PEM_R_UNSUPPORTED_CIPHER}, - #else - {"UNSUPPORTED_CIPHER", ERR_LIB_PEM, 113}, - #endif - #ifdef PEM_R_UNSUPPORTED_ENCRYPTION - {"UNSUPPORTED_ENCRYPTION", ERR_LIB_PEM, PEM_R_UNSUPPORTED_ENCRYPTION}, - #else - {"UNSUPPORTED_ENCRYPTION", ERR_LIB_PEM, 114}, - #endif - #ifdef PEM_R_UNSUPPORTED_KEY_COMPONENTS - {"UNSUPPORTED_KEY_COMPONENTS", ERR_LIB_PEM, PEM_R_UNSUPPORTED_KEY_COMPONENTS}, - #else - {"UNSUPPORTED_KEY_COMPONENTS", ERR_LIB_PEM, 126}, - #endif - #ifdef SSL_R_APP_DATA_IN_HANDSHAKE - {"APP_DATA_IN_HANDSHAKE", ERR_LIB_SSL, SSL_R_APP_DATA_IN_HANDSHAKE}, - #else - {"APP_DATA_IN_HANDSHAKE", ERR_LIB_SSL, 100}, - #endif - #ifdef SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT - {"ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT", ERR_LIB_SSL, SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT}, - #else - {"ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT", ERR_LIB_SSL, 272}, - #endif - #ifdef SSL_R_BAD_ALERT_RECORD - {"BAD_ALERT_RECORD", ERR_LIB_SSL, SSL_R_BAD_ALERT_RECORD}, - #else - {"BAD_ALERT_RECORD", ERR_LIB_SSL, 101}, - #endif - #ifdef SSL_R_BAD_AUTHENTICATION_TYPE - {"BAD_AUTHENTICATION_TYPE", ERR_LIB_SSL, SSL_R_BAD_AUTHENTICATION_TYPE}, - #else - {"BAD_AUTHENTICATION_TYPE", ERR_LIB_SSL, 102}, - #endif - #ifdef SSL_R_BAD_CHANGE_CIPHER_SPEC - {"BAD_CHANGE_CIPHER_SPEC", ERR_LIB_SSL, SSL_R_BAD_CHANGE_CIPHER_SPEC}, - #else - {"BAD_CHANGE_CIPHER_SPEC", ERR_LIB_SSL, 103}, - #endif - #ifdef SSL_R_BAD_CHECKSUM - {"BAD_CHECKSUM", ERR_LIB_SSL, SSL_R_BAD_CHECKSUM}, - #else - {"BAD_CHECKSUM", ERR_LIB_SSL, 104}, - #endif - #ifdef SSL_R_BAD_DATA - {"BAD_DATA", ERR_LIB_SSL, SSL_R_BAD_DATA}, - #else - {"BAD_DATA", ERR_LIB_SSL, 390}, - #endif - #ifdef SSL_R_BAD_DATA_RETURNED_BY_CALLBACK - {"BAD_DATA_RETURNED_BY_CALLBACK", ERR_LIB_SSL, SSL_R_BAD_DATA_RETURNED_BY_CALLBACK}, - #else - {"BAD_DATA_RETURNED_BY_CALLBACK", ERR_LIB_SSL, 106}, - #endif - #ifdef SSL_R_BAD_DECOMPRESSION - {"BAD_DECOMPRESSION", ERR_LIB_SSL, SSL_R_BAD_DECOMPRESSION}, - #else - {"BAD_DECOMPRESSION", ERR_LIB_SSL, 107}, - #endif - #ifdef SSL_R_BAD_DH_G_LENGTH - {"BAD_DH_G_LENGTH", ERR_LIB_SSL, SSL_R_BAD_DH_G_LENGTH}, - #else - {"BAD_DH_G_LENGTH", ERR_LIB_SSL, 108}, - #endif - #ifdef SSL_R_BAD_DH_PUB_KEY_LENGTH - {"BAD_DH_PUB_KEY_LENGTH", ERR_LIB_SSL, SSL_R_BAD_DH_PUB_KEY_LENGTH}, - #else - {"BAD_DH_PUB_KEY_LENGTH", ERR_LIB_SSL, 109}, - #endif - #ifdef SSL_R_BAD_DH_P_LENGTH - {"BAD_DH_P_LENGTH", ERR_LIB_SSL, SSL_R_BAD_DH_P_LENGTH}, - #else - {"BAD_DH_P_LENGTH", ERR_LIB_SSL, 110}, - #endif - #ifdef SSL_R_BAD_DIGEST_LENGTH - {"BAD_DIGEST_LENGTH", ERR_LIB_SSL, SSL_R_BAD_DIGEST_LENGTH}, - #else - {"BAD_DIGEST_LENGTH", ERR_LIB_SSL, 111}, - #endif - #ifdef SSL_R_BAD_DSA_SIGNATURE - {"BAD_DSA_SIGNATURE", ERR_LIB_SSL, SSL_R_BAD_DSA_SIGNATURE}, - #else - {"BAD_DSA_SIGNATURE", ERR_LIB_SSL, 112}, - #endif - #ifdef SSL_R_BAD_ECC_CERT - {"BAD_ECC_CERT", ERR_LIB_SSL, SSL_R_BAD_ECC_CERT}, - #else - {"BAD_ECC_CERT", ERR_LIB_SSL, 304}, - #endif - #ifdef SSL_R_BAD_ECDSA_SIGNATURE - {"BAD_ECDSA_SIGNATURE", ERR_LIB_SSL, SSL_R_BAD_ECDSA_SIGNATURE}, - #else - {"BAD_ECDSA_SIGNATURE", ERR_LIB_SSL, 305}, - #endif - #ifdef SSL_R_BAD_ECPOINT - {"BAD_ECPOINT", ERR_LIB_SSL, SSL_R_BAD_ECPOINT}, - #else - {"BAD_ECPOINT", ERR_LIB_SSL, 306}, - #endif - #ifdef SSL_R_BAD_HANDSHAKE_LENGTH - {"BAD_HANDSHAKE_LENGTH", ERR_LIB_SSL, SSL_R_BAD_HANDSHAKE_LENGTH}, - #else - {"BAD_HANDSHAKE_LENGTH", ERR_LIB_SSL, 332}, - #endif - #ifdef SSL_R_BAD_HELLO_REQUEST - {"BAD_HELLO_REQUEST", ERR_LIB_SSL, SSL_R_BAD_HELLO_REQUEST}, - #else - {"BAD_HELLO_REQUEST", ERR_LIB_SSL, 105}, - #endif - #ifdef SSL_R_BAD_LENGTH - {"BAD_LENGTH", ERR_LIB_SSL, SSL_R_BAD_LENGTH}, - #else - {"BAD_LENGTH", ERR_LIB_SSL, 271}, - #endif - #ifdef SSL_R_BAD_MAC_DECODE - {"BAD_MAC_DECODE", ERR_LIB_SSL, SSL_R_BAD_MAC_DECODE}, - #else - {"BAD_MAC_DECODE", ERR_LIB_SSL, 113}, - #endif - #ifdef SSL_R_BAD_MAC_LENGTH - {"BAD_MAC_LENGTH", ERR_LIB_SSL, SSL_R_BAD_MAC_LENGTH}, - #else - {"BAD_MAC_LENGTH", ERR_LIB_SSL, 333}, - #endif - #ifdef SSL_R_BAD_MESSAGE_TYPE - {"BAD_MESSAGE_TYPE", ERR_LIB_SSL, SSL_R_BAD_MESSAGE_TYPE}, - #else - {"BAD_MESSAGE_TYPE", ERR_LIB_SSL, 114}, - #endif - #ifdef SSL_R_BAD_PACKET_LENGTH - {"BAD_PACKET_LENGTH", ERR_LIB_SSL, SSL_R_BAD_PACKET_LENGTH}, - #else - {"BAD_PACKET_LENGTH", ERR_LIB_SSL, 115}, - #endif - #ifdef SSL_R_BAD_PROTOCOL_VERSION_NUMBER - {"BAD_PROTOCOL_VERSION_NUMBER", ERR_LIB_SSL, SSL_R_BAD_PROTOCOL_VERSION_NUMBER}, - #else - {"BAD_PROTOCOL_VERSION_NUMBER", ERR_LIB_SSL, 116}, - #endif - #ifdef SSL_R_BAD_PSK_IDENTITY_HINT_LENGTH - {"BAD_PSK_IDENTITY_HINT_LENGTH", ERR_LIB_SSL, SSL_R_BAD_PSK_IDENTITY_HINT_LENGTH}, - #else - {"BAD_PSK_IDENTITY_HINT_LENGTH", ERR_LIB_SSL, 316}, - #endif - #ifdef SSL_R_BAD_RESPONSE_ARGUMENT - {"BAD_RESPONSE_ARGUMENT", ERR_LIB_SSL, SSL_R_BAD_RESPONSE_ARGUMENT}, - #else - {"BAD_RESPONSE_ARGUMENT", ERR_LIB_SSL, 117}, - #endif - #ifdef SSL_R_BAD_RSA_DECRYPT - {"BAD_RSA_DECRYPT", ERR_LIB_SSL, SSL_R_BAD_RSA_DECRYPT}, - #else - {"BAD_RSA_DECRYPT", ERR_LIB_SSL, 118}, - #endif - #ifdef SSL_R_BAD_RSA_ENCRYPT - {"BAD_RSA_ENCRYPT", ERR_LIB_SSL, SSL_R_BAD_RSA_ENCRYPT}, - #else - {"BAD_RSA_ENCRYPT", ERR_LIB_SSL, 119}, - #endif - #ifdef SSL_R_BAD_RSA_E_LENGTH - {"BAD_RSA_E_LENGTH", ERR_LIB_SSL, SSL_R_BAD_RSA_E_LENGTH}, - #else - {"BAD_RSA_E_LENGTH", ERR_LIB_SSL, 120}, - #endif - #ifdef SSL_R_BAD_RSA_MODULUS_LENGTH - {"BAD_RSA_MODULUS_LENGTH", ERR_LIB_SSL, SSL_R_BAD_RSA_MODULUS_LENGTH}, - #else - {"BAD_RSA_MODULUS_LENGTH", ERR_LIB_SSL, 121}, - #endif - #ifdef SSL_R_BAD_RSA_SIGNATURE - {"BAD_RSA_SIGNATURE", ERR_LIB_SSL, SSL_R_BAD_RSA_SIGNATURE}, - #else - {"BAD_RSA_SIGNATURE", ERR_LIB_SSL, 122}, - #endif - #ifdef SSL_R_BAD_SIGNATURE - {"BAD_SIGNATURE", ERR_LIB_SSL, SSL_R_BAD_SIGNATURE}, - #else - {"BAD_SIGNATURE", ERR_LIB_SSL, 123}, - #endif - #ifdef SSL_R_BAD_SRP_A_LENGTH - {"BAD_SRP_A_LENGTH", ERR_LIB_SSL, SSL_R_BAD_SRP_A_LENGTH}, - #else - {"BAD_SRP_A_LENGTH", ERR_LIB_SSL, 347}, - #endif - #ifdef SSL_R_BAD_SRP_B_LENGTH - {"BAD_SRP_B_LENGTH", ERR_LIB_SSL, SSL_R_BAD_SRP_B_LENGTH}, - #else - {"BAD_SRP_B_LENGTH", ERR_LIB_SSL, 348}, - #endif - #ifdef SSL_R_BAD_SRP_G_LENGTH - {"BAD_SRP_G_LENGTH", ERR_LIB_SSL, SSL_R_BAD_SRP_G_LENGTH}, - #else - {"BAD_SRP_G_LENGTH", ERR_LIB_SSL, 349}, - #endif - #ifdef SSL_R_BAD_SRP_N_LENGTH - {"BAD_SRP_N_LENGTH", ERR_LIB_SSL, SSL_R_BAD_SRP_N_LENGTH}, - #else - {"BAD_SRP_N_LENGTH", ERR_LIB_SSL, 350}, - #endif - #ifdef SSL_R_BAD_SRP_PARAMETERS - {"BAD_SRP_PARAMETERS", ERR_LIB_SSL, SSL_R_BAD_SRP_PARAMETERS}, - #else - {"BAD_SRP_PARAMETERS", ERR_LIB_SSL, 371}, - #endif - #ifdef SSL_R_BAD_SRP_S_LENGTH - {"BAD_SRP_S_LENGTH", ERR_LIB_SSL, SSL_R_BAD_SRP_S_LENGTH}, - #else - {"BAD_SRP_S_LENGTH", ERR_LIB_SSL, 351}, - #endif - #ifdef SSL_R_BAD_SRTP_MKI_VALUE - {"BAD_SRTP_MKI_VALUE", ERR_LIB_SSL, SSL_R_BAD_SRTP_MKI_VALUE}, - #else - {"BAD_SRTP_MKI_VALUE", ERR_LIB_SSL, 352}, - #endif - #ifdef SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST - {"BAD_SRTP_PROTECTION_PROFILE_LIST", ERR_LIB_SSL, SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST}, - #else - {"BAD_SRTP_PROTECTION_PROFILE_LIST", ERR_LIB_SSL, 353}, - #endif - #ifdef SSL_R_BAD_SSL_FILETYPE - {"BAD_SSL_FILETYPE", ERR_LIB_SSL, SSL_R_BAD_SSL_FILETYPE}, - #else - {"BAD_SSL_FILETYPE", ERR_LIB_SSL, 124}, - #endif - #ifdef SSL_R_BAD_SSL_SESSION_ID_LENGTH - {"BAD_SSL_SESSION_ID_LENGTH", ERR_LIB_SSL, SSL_R_BAD_SSL_SESSION_ID_LENGTH}, - #else - {"BAD_SSL_SESSION_ID_LENGTH", ERR_LIB_SSL, 125}, - #endif - #ifdef SSL_R_BAD_STATE - {"BAD_STATE", ERR_LIB_SSL, SSL_R_BAD_STATE}, - #else - {"BAD_STATE", ERR_LIB_SSL, 126}, - #endif - #ifdef SSL_R_BAD_VALUE - {"BAD_VALUE", ERR_LIB_SSL, SSL_R_BAD_VALUE}, - #else - {"BAD_VALUE", ERR_LIB_SSL, 384}, - #endif - #ifdef SSL_R_BAD_WRITE_RETRY - {"BAD_WRITE_RETRY", ERR_LIB_SSL, SSL_R_BAD_WRITE_RETRY}, - #else - {"BAD_WRITE_RETRY", ERR_LIB_SSL, 127}, - #endif - #ifdef SSL_R_BIO_NOT_SET - {"BIO_NOT_SET", ERR_LIB_SSL, SSL_R_BIO_NOT_SET}, - #else - {"BIO_NOT_SET", ERR_LIB_SSL, 128}, - #endif - #ifdef SSL_R_BLOCK_CIPHER_PAD_IS_WRONG - {"BLOCK_CIPHER_PAD_IS_WRONG", ERR_LIB_SSL, SSL_R_BLOCK_CIPHER_PAD_IS_WRONG}, - #else - {"BLOCK_CIPHER_PAD_IS_WRONG", ERR_LIB_SSL, 129}, - #endif - #ifdef SSL_R_BN_LIB - {"BN_LIB", ERR_LIB_SSL, SSL_R_BN_LIB}, - #else - {"BN_LIB", ERR_LIB_SSL, 130}, - #endif - #ifdef SSL_R_CA_DN_LENGTH_MISMATCH - {"CA_DN_LENGTH_MISMATCH", ERR_LIB_SSL, SSL_R_CA_DN_LENGTH_MISMATCH}, - #else - {"CA_DN_LENGTH_MISMATCH", ERR_LIB_SSL, 131}, - #endif - #ifdef SSL_R_CA_DN_TOO_LONG - {"CA_DN_TOO_LONG", ERR_LIB_SSL, SSL_R_CA_DN_TOO_LONG}, - #else - {"CA_DN_TOO_LONG", ERR_LIB_SSL, 132}, - #endif - #ifdef SSL_R_CA_KEY_TOO_SMALL - {"CA_KEY_TOO_SMALL", ERR_LIB_SSL, SSL_R_CA_KEY_TOO_SMALL}, - #else - {"CA_KEY_TOO_SMALL", ERR_LIB_SSL, 397}, - #endif - #ifdef SSL_R_CA_MD_TOO_WEAK - {"CA_MD_TOO_WEAK", ERR_LIB_SSL, SSL_R_CA_MD_TOO_WEAK}, - #else - {"CA_MD_TOO_WEAK", ERR_LIB_SSL, 398}, - #endif - #ifdef SSL_R_CCS_RECEIVED_EARLY - {"CCS_RECEIVED_EARLY", ERR_LIB_SSL, SSL_R_CCS_RECEIVED_EARLY}, - #else - {"CCS_RECEIVED_EARLY", ERR_LIB_SSL, 133}, - #endif - #ifdef SSL_R_CERTIFICATE_VERIFY_FAILED - {"CERTIFICATE_VERIFY_FAILED", ERR_LIB_SSL, SSL_R_CERTIFICATE_VERIFY_FAILED}, - #else - {"CERTIFICATE_VERIFY_FAILED", ERR_LIB_SSL, 134}, - #endif - #ifdef SSL_R_CERT_CB_ERROR - {"CERT_CB_ERROR", ERR_LIB_SSL, SSL_R_CERT_CB_ERROR}, - #else - {"CERT_CB_ERROR", ERR_LIB_SSL, 377}, - #endif - #ifdef SSL_R_CERT_LENGTH_MISMATCH - {"CERT_LENGTH_MISMATCH", ERR_LIB_SSL, SSL_R_CERT_LENGTH_MISMATCH}, - #else - {"CERT_LENGTH_MISMATCH", ERR_LIB_SSL, 135}, - #endif - #ifdef SSL_R_CHALLENGE_IS_DIFFERENT - {"CHALLENGE_IS_DIFFERENT", ERR_LIB_SSL, SSL_R_CHALLENGE_IS_DIFFERENT}, - #else - {"CHALLENGE_IS_DIFFERENT", ERR_LIB_SSL, 136}, - #endif - #ifdef SSL_R_CIPHER_CODE_WRONG_LENGTH - {"CIPHER_CODE_WRONG_LENGTH", ERR_LIB_SSL, SSL_R_CIPHER_CODE_WRONG_LENGTH}, - #else - {"CIPHER_CODE_WRONG_LENGTH", ERR_LIB_SSL, 137}, - #endif - #ifdef SSL_R_CIPHER_OR_HASH_UNAVAILABLE - {"CIPHER_OR_HASH_UNAVAILABLE", ERR_LIB_SSL, SSL_R_CIPHER_OR_HASH_UNAVAILABLE}, - #else - {"CIPHER_OR_HASH_UNAVAILABLE", ERR_LIB_SSL, 138}, - #endif - #ifdef SSL_R_CIPHER_TABLE_SRC_ERROR - {"CIPHER_TABLE_SRC_ERROR", ERR_LIB_SSL, SSL_R_CIPHER_TABLE_SRC_ERROR}, - #else - {"CIPHER_TABLE_SRC_ERROR", ERR_LIB_SSL, 139}, - #endif - #ifdef SSL_R_CLIENTHELLO_TLSEXT - {"CLIENTHELLO_TLSEXT", ERR_LIB_SSL, SSL_R_CLIENTHELLO_TLSEXT}, - #else - {"CLIENTHELLO_TLSEXT", ERR_LIB_SSL, 226}, - #endif - #ifdef SSL_R_COMPRESSED_LENGTH_TOO_LONG - {"COMPRESSED_LENGTH_TOO_LONG", ERR_LIB_SSL, SSL_R_COMPRESSED_LENGTH_TOO_LONG}, - #else - {"COMPRESSED_LENGTH_TOO_LONG", ERR_LIB_SSL, 140}, - #endif - #ifdef SSL_R_COMPRESSION_DISABLED - {"COMPRESSION_DISABLED", ERR_LIB_SSL, SSL_R_COMPRESSION_DISABLED}, - #else - {"COMPRESSION_DISABLED", ERR_LIB_SSL, 343}, - #endif - #ifdef SSL_R_COMPRESSION_FAILURE - {"COMPRESSION_FAILURE", ERR_LIB_SSL, SSL_R_COMPRESSION_FAILURE}, - #else - {"COMPRESSION_FAILURE", ERR_LIB_SSL, 141}, - #endif - #ifdef SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE - {"COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE", ERR_LIB_SSL, SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE}, - #else - {"COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE", ERR_LIB_SSL, 307}, - #endif - #ifdef SSL_R_COMPRESSION_LIBRARY_ERROR - {"COMPRESSION_LIBRARY_ERROR", ERR_LIB_SSL, SSL_R_COMPRESSION_LIBRARY_ERROR}, - #else - {"COMPRESSION_LIBRARY_ERROR", ERR_LIB_SSL, 142}, - #endif - #ifdef SSL_R_CONNECTION_ID_IS_DIFFERENT - {"CONNECTION_ID_IS_DIFFERENT", ERR_LIB_SSL, SSL_R_CONNECTION_ID_IS_DIFFERENT}, - #else - {"CONNECTION_ID_IS_DIFFERENT", ERR_LIB_SSL, 143}, - #endif - #ifdef SSL_R_CONNECTION_TYPE_NOT_SET - {"CONNECTION_TYPE_NOT_SET", ERR_LIB_SSL, SSL_R_CONNECTION_TYPE_NOT_SET}, - #else - {"CONNECTION_TYPE_NOT_SET", ERR_LIB_SSL, 144}, - #endif - #ifdef SSL_R_COOKIE_MISMATCH - {"COOKIE_MISMATCH", ERR_LIB_SSL, SSL_R_COOKIE_MISMATCH}, - #else - {"COOKIE_MISMATCH", ERR_LIB_SSL, 308}, - #endif - #ifdef SSL_R_DATA_BETWEEN_CCS_AND_FINISHED - {"DATA_BETWEEN_CCS_AND_FINISHED", ERR_LIB_SSL, SSL_R_DATA_BETWEEN_CCS_AND_FINISHED}, - #else - {"DATA_BETWEEN_CCS_AND_FINISHED", ERR_LIB_SSL, 145}, - #endif - #ifdef SSL_R_DATA_LENGTH_TOO_LONG - {"DATA_LENGTH_TOO_LONG", ERR_LIB_SSL, SSL_R_DATA_LENGTH_TOO_LONG}, - #else - {"DATA_LENGTH_TOO_LONG", ERR_LIB_SSL, 146}, - #endif - #ifdef SSL_R_DECRYPTION_FAILED - {"DECRYPTION_FAILED", ERR_LIB_SSL, SSL_R_DECRYPTION_FAILED}, - #else - {"DECRYPTION_FAILED", ERR_LIB_SSL, 147}, - #endif - #ifdef SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC - {"DECRYPTION_FAILED_OR_BAD_RECORD_MAC", ERR_LIB_SSL, SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC}, - #else - {"DECRYPTION_FAILED_OR_BAD_RECORD_MAC", ERR_LIB_SSL, 281}, - #endif - #ifdef SSL_R_DH_KEY_TOO_SMALL - {"DH_KEY_TOO_SMALL", ERR_LIB_SSL, SSL_R_DH_KEY_TOO_SMALL}, - #else - {"DH_KEY_TOO_SMALL", ERR_LIB_SSL, 394}, - #endif - #ifdef SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG - {"DH_PUBLIC_VALUE_LENGTH_IS_WRONG", ERR_LIB_SSL, SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG}, - #else - {"DH_PUBLIC_VALUE_LENGTH_IS_WRONG", ERR_LIB_SSL, 148}, - #endif - #ifdef SSL_R_DIGEST_CHECK_FAILED - {"DIGEST_CHECK_FAILED", ERR_LIB_SSL, SSL_R_DIGEST_CHECK_FAILED}, - #else - {"DIGEST_CHECK_FAILED", ERR_LIB_SSL, 149}, - #endif - #ifdef SSL_R_DTLS_MESSAGE_TOO_BIG - {"DTLS_MESSAGE_TOO_BIG", ERR_LIB_SSL, SSL_R_DTLS_MESSAGE_TOO_BIG}, - #else - {"DTLS_MESSAGE_TOO_BIG", ERR_LIB_SSL, 334}, - #endif - #ifdef SSL_R_DUPLICATE_COMPRESSION_ID - {"DUPLICATE_COMPRESSION_ID", ERR_LIB_SSL, SSL_R_DUPLICATE_COMPRESSION_ID}, - #else - {"DUPLICATE_COMPRESSION_ID", ERR_LIB_SSL, 309}, - #endif - #ifdef SSL_R_ECC_CERT_NOT_FOR_KEY_AGREEMENT - {"ECC_CERT_NOT_FOR_KEY_AGREEMENT", ERR_LIB_SSL, SSL_R_ECC_CERT_NOT_FOR_KEY_AGREEMENT}, - #else - {"ECC_CERT_NOT_FOR_KEY_AGREEMENT", ERR_LIB_SSL, 317}, - #endif - #ifdef SSL_R_ECC_CERT_NOT_FOR_SIGNING - {"ECC_CERT_NOT_FOR_SIGNING", ERR_LIB_SSL, SSL_R_ECC_CERT_NOT_FOR_SIGNING}, - #else - {"ECC_CERT_NOT_FOR_SIGNING", ERR_LIB_SSL, 318}, - #endif - #ifdef SSL_R_ECC_CERT_SHOULD_HAVE_RSA_SIGNATURE - {"ECC_CERT_SHOULD_HAVE_RSA_SIGNATURE", ERR_LIB_SSL, SSL_R_ECC_CERT_SHOULD_HAVE_RSA_SIGNATURE}, - #else - {"ECC_CERT_SHOULD_HAVE_RSA_SIGNATURE", ERR_LIB_SSL, 322}, - #endif - #ifdef SSL_R_ECC_CERT_SHOULD_HAVE_SHA1_SIGNATURE - {"ECC_CERT_SHOULD_HAVE_SHA1_SIGNATURE", ERR_LIB_SSL, SSL_R_ECC_CERT_SHOULD_HAVE_SHA1_SIGNATURE}, - #else - {"ECC_CERT_SHOULD_HAVE_SHA1_SIGNATURE", ERR_LIB_SSL, 323}, - #endif - #ifdef SSL_R_ECDH_REQUIRED_FOR_SUITEB_MODE - {"ECDH_REQUIRED_FOR_SUITEB_MODE", ERR_LIB_SSL, SSL_R_ECDH_REQUIRED_FOR_SUITEB_MODE}, - #else - {"ECDH_REQUIRED_FOR_SUITEB_MODE", ERR_LIB_SSL, 374}, - #endif - #ifdef SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER - {"ECGROUP_TOO_LARGE_FOR_CIPHER", ERR_LIB_SSL, SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER}, - #else - {"ECGROUP_TOO_LARGE_FOR_CIPHER", ERR_LIB_SSL, 310}, - #endif - #ifdef SSL_R_EE_KEY_TOO_SMALL - {"EE_KEY_TOO_SMALL", ERR_LIB_SSL, SSL_R_EE_KEY_TOO_SMALL}, - #else - {"EE_KEY_TOO_SMALL", ERR_LIB_SSL, 399}, - #endif - #ifdef SSL_R_EMPTY_SRTP_PROTECTION_PROFILE_LIST - {"EMPTY_SRTP_PROTECTION_PROFILE_LIST", ERR_LIB_SSL, SSL_R_EMPTY_SRTP_PROTECTION_PROFILE_LIST}, - #else - {"EMPTY_SRTP_PROTECTION_PROFILE_LIST", ERR_LIB_SSL, 354}, - #endif - #ifdef SSL_R_ENCRYPTED_LENGTH_TOO_LONG - {"ENCRYPTED_LENGTH_TOO_LONG", ERR_LIB_SSL, SSL_R_ENCRYPTED_LENGTH_TOO_LONG}, - #else - {"ENCRYPTED_LENGTH_TOO_LONG", ERR_LIB_SSL, 150}, - #endif - #ifdef SSL_R_ERROR_GENERATING_TMP_RSA_KEY - {"ERROR_GENERATING_TMP_RSA_KEY", ERR_LIB_SSL, SSL_R_ERROR_GENERATING_TMP_RSA_KEY}, - #else - {"ERROR_GENERATING_TMP_RSA_KEY", ERR_LIB_SSL, 282}, - #endif - #ifdef SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST - {"ERROR_IN_RECEIVED_CIPHER_LIST", ERR_LIB_SSL, SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST}, - #else - {"ERROR_IN_RECEIVED_CIPHER_LIST", ERR_LIB_SSL, 151}, - #endif - #ifdef SSL_R_EXCESSIVE_MESSAGE_SIZE - {"EXCESSIVE_MESSAGE_SIZE", ERR_LIB_SSL, SSL_R_EXCESSIVE_MESSAGE_SIZE}, - #else - {"EXCESSIVE_MESSAGE_SIZE", ERR_LIB_SSL, 152}, - #endif - #ifdef SSL_R_EXTRA_DATA_IN_MESSAGE - {"EXTRA_DATA_IN_MESSAGE", ERR_LIB_SSL, SSL_R_EXTRA_DATA_IN_MESSAGE}, - #else - {"EXTRA_DATA_IN_MESSAGE", ERR_LIB_SSL, 153}, - #endif - #ifdef SSL_R_GOT_A_FIN_BEFORE_A_CCS - {"GOT_A_FIN_BEFORE_A_CCS", ERR_LIB_SSL, SSL_R_GOT_A_FIN_BEFORE_A_CCS}, - #else - {"GOT_A_FIN_BEFORE_A_CCS", ERR_LIB_SSL, 154}, - #endif - #ifdef SSL_R_GOT_NEXT_PROTO_BEFORE_A_CCS - {"GOT_NEXT_PROTO_BEFORE_A_CCS", ERR_LIB_SSL, SSL_R_GOT_NEXT_PROTO_BEFORE_A_CCS}, - #else - {"GOT_NEXT_PROTO_BEFORE_A_CCS", ERR_LIB_SSL, 355}, - #endif - #ifdef SSL_R_GOT_NEXT_PROTO_WITHOUT_EXTENSION - {"GOT_NEXT_PROTO_WITHOUT_EXTENSION", ERR_LIB_SSL, SSL_R_GOT_NEXT_PROTO_WITHOUT_EXTENSION}, - #else - {"GOT_NEXT_PROTO_WITHOUT_EXTENSION", ERR_LIB_SSL, 356}, - #endif - #ifdef SSL_R_HTTPS_PROXY_REQUEST - {"HTTPS_PROXY_REQUEST", ERR_LIB_SSL, SSL_R_HTTPS_PROXY_REQUEST}, - #else - {"HTTPS_PROXY_REQUEST", ERR_LIB_SSL, 155}, - #endif - #ifdef SSL_R_HTTP_REQUEST - {"HTTP_REQUEST", ERR_LIB_SSL, SSL_R_HTTP_REQUEST}, - #else - {"HTTP_REQUEST", ERR_LIB_SSL, 156}, - #endif - #ifdef SSL_R_ILLEGAL_PADDING - {"ILLEGAL_PADDING", ERR_LIB_SSL, SSL_R_ILLEGAL_PADDING}, - #else - {"ILLEGAL_PADDING", ERR_LIB_SSL, 283}, - #endif - #ifdef SSL_R_ILLEGAL_SUITEB_DIGEST - {"ILLEGAL_SUITEB_DIGEST", ERR_LIB_SSL, SSL_R_ILLEGAL_SUITEB_DIGEST}, - #else - {"ILLEGAL_SUITEB_DIGEST", ERR_LIB_SSL, 380}, - #endif - #ifdef SSL_R_INAPPROPRIATE_FALLBACK - {"INAPPROPRIATE_FALLBACK", ERR_LIB_SSL, SSL_R_INAPPROPRIATE_FALLBACK}, - #else - {"INAPPROPRIATE_FALLBACK", ERR_LIB_SSL, 373}, - #endif - #ifdef SSL_R_INCONSISTENT_COMPRESSION - {"INCONSISTENT_COMPRESSION", ERR_LIB_SSL, SSL_R_INCONSISTENT_COMPRESSION}, - #else - {"INCONSISTENT_COMPRESSION", ERR_LIB_SSL, 340}, - #endif - #ifdef SSL_R_INVALID_CHALLENGE_LENGTH - {"INVALID_CHALLENGE_LENGTH", ERR_LIB_SSL, SSL_R_INVALID_CHALLENGE_LENGTH}, - #else - {"INVALID_CHALLENGE_LENGTH", ERR_LIB_SSL, 158}, - #endif - #ifdef SSL_R_INVALID_COMMAND - {"INVALID_COMMAND", ERR_LIB_SSL, SSL_R_INVALID_COMMAND}, - #else - {"INVALID_COMMAND", ERR_LIB_SSL, 280}, - #endif - #ifdef SSL_R_INVALID_COMPRESSION_ALGORITHM - {"INVALID_COMPRESSION_ALGORITHM", ERR_LIB_SSL, SSL_R_INVALID_COMPRESSION_ALGORITHM}, - #else - {"INVALID_COMPRESSION_ALGORITHM", ERR_LIB_SSL, 341}, - #endif - #ifdef SSL_R_INVALID_NULL_CMD_NAME - {"INVALID_NULL_CMD_NAME", ERR_LIB_SSL, SSL_R_INVALID_NULL_CMD_NAME}, - #else - {"INVALID_NULL_CMD_NAME", ERR_LIB_SSL, 385}, - #endif - #ifdef SSL_R_INVALID_PURPOSE - {"INVALID_PURPOSE", ERR_LIB_SSL, SSL_R_INVALID_PURPOSE}, - #else - {"INVALID_PURPOSE", ERR_LIB_SSL, 278}, - #endif - #ifdef SSL_R_INVALID_SERVERINFO_DATA - {"INVALID_SERVERINFO_DATA", ERR_LIB_SSL, SSL_R_INVALID_SERVERINFO_DATA}, - #else - {"INVALID_SERVERINFO_DATA", ERR_LIB_SSL, 388}, - #endif - #ifdef SSL_R_INVALID_SRP_USERNAME - {"INVALID_SRP_USERNAME", ERR_LIB_SSL, SSL_R_INVALID_SRP_USERNAME}, - #else - {"INVALID_SRP_USERNAME", ERR_LIB_SSL, 357}, - #endif - #ifdef SSL_R_INVALID_STATUS_RESPONSE - {"INVALID_STATUS_RESPONSE", ERR_LIB_SSL, SSL_R_INVALID_STATUS_RESPONSE}, - #else - {"INVALID_STATUS_RESPONSE", ERR_LIB_SSL, 328}, - #endif - #ifdef SSL_R_INVALID_TICKET_KEYS_LENGTH - {"INVALID_TICKET_KEYS_LENGTH", ERR_LIB_SSL, SSL_R_INVALID_TICKET_KEYS_LENGTH}, - #else - {"INVALID_TICKET_KEYS_LENGTH", ERR_LIB_SSL, 325}, - #endif - #ifdef SSL_R_INVALID_TRUST - {"INVALID_TRUST", ERR_LIB_SSL, SSL_R_INVALID_TRUST}, - #else - {"INVALID_TRUST", ERR_LIB_SSL, 279}, - #endif - #ifdef SSL_R_KEY_ARG_TOO_LONG - {"KEY_ARG_TOO_LONG", ERR_LIB_SSL, SSL_R_KEY_ARG_TOO_LONG}, - #else - {"KEY_ARG_TOO_LONG", ERR_LIB_SSL, 284}, - #endif - #ifdef SSL_R_KRB5 - {"KRB5", ERR_LIB_SSL, SSL_R_KRB5}, - #else - {"KRB5", ERR_LIB_SSL, 285}, - #endif - #ifdef SSL_R_KRB5_C_CC_PRINC - {"KRB5_C_CC_PRINC", ERR_LIB_SSL, SSL_R_KRB5_C_CC_PRINC}, - #else - {"KRB5_C_CC_PRINC", ERR_LIB_SSL, 286}, - #endif - #ifdef SSL_R_KRB5_C_GET_CRED - {"KRB5_C_GET_CRED", ERR_LIB_SSL, SSL_R_KRB5_C_GET_CRED}, - #else - {"KRB5_C_GET_CRED", ERR_LIB_SSL, 287}, - #endif - #ifdef SSL_R_KRB5_C_INIT - {"KRB5_C_INIT", ERR_LIB_SSL, SSL_R_KRB5_C_INIT}, - #else - {"KRB5_C_INIT", ERR_LIB_SSL, 288}, - #endif - #ifdef SSL_R_KRB5_C_MK_REQ - {"KRB5_C_MK_REQ", ERR_LIB_SSL, SSL_R_KRB5_C_MK_REQ}, - #else - {"KRB5_C_MK_REQ", ERR_LIB_SSL, 289}, - #endif - #ifdef SSL_R_KRB5_S_BAD_TICKET - {"KRB5_S_BAD_TICKET", ERR_LIB_SSL, SSL_R_KRB5_S_BAD_TICKET}, - #else - {"KRB5_S_BAD_TICKET", ERR_LIB_SSL, 290}, - #endif - #ifdef SSL_R_KRB5_S_INIT - {"KRB5_S_INIT", ERR_LIB_SSL, SSL_R_KRB5_S_INIT}, - #else - {"KRB5_S_INIT", ERR_LIB_SSL, 291}, - #endif - #ifdef SSL_R_KRB5_S_RD_REQ - {"KRB5_S_RD_REQ", ERR_LIB_SSL, SSL_R_KRB5_S_RD_REQ}, - #else - {"KRB5_S_RD_REQ", ERR_LIB_SSL, 292}, - #endif - #ifdef SSL_R_KRB5_S_TKT_EXPIRED - {"KRB5_S_TKT_EXPIRED", ERR_LIB_SSL, SSL_R_KRB5_S_TKT_EXPIRED}, - #else - {"KRB5_S_TKT_EXPIRED", ERR_LIB_SSL, 293}, - #endif - #ifdef SSL_R_KRB5_S_TKT_NYV - {"KRB5_S_TKT_NYV", ERR_LIB_SSL, SSL_R_KRB5_S_TKT_NYV}, - #else - {"KRB5_S_TKT_NYV", ERR_LIB_SSL, 294}, - #endif - #ifdef SSL_R_KRB5_S_TKT_SKEW - {"KRB5_S_TKT_SKEW", ERR_LIB_SSL, SSL_R_KRB5_S_TKT_SKEW}, - #else - {"KRB5_S_TKT_SKEW", ERR_LIB_SSL, 295}, - #endif - #ifdef SSL_R_LENGTH_MISMATCH - {"LENGTH_MISMATCH", ERR_LIB_SSL, SSL_R_LENGTH_MISMATCH}, - #else - {"LENGTH_MISMATCH", ERR_LIB_SSL, 159}, - #endif - #ifdef SSL_R_LENGTH_TOO_SHORT - {"LENGTH_TOO_SHORT", ERR_LIB_SSL, SSL_R_LENGTH_TOO_SHORT}, - #else - {"LENGTH_TOO_SHORT", ERR_LIB_SSL, 160}, - #endif - #ifdef SSL_R_LIBRARY_BUG - {"LIBRARY_BUG", ERR_LIB_SSL, SSL_R_LIBRARY_BUG}, - #else - {"LIBRARY_BUG", ERR_LIB_SSL, 274}, - #endif - #ifdef SSL_R_LIBRARY_HAS_NO_CIPHERS - {"LIBRARY_HAS_NO_CIPHERS", ERR_LIB_SSL, SSL_R_LIBRARY_HAS_NO_CIPHERS}, - #else - {"LIBRARY_HAS_NO_CIPHERS", ERR_LIB_SSL, 161}, - #endif - #ifdef SSL_R_MESSAGE_TOO_LONG - {"MESSAGE_TOO_LONG", ERR_LIB_SSL, SSL_R_MESSAGE_TOO_LONG}, - #else - {"MESSAGE_TOO_LONG", ERR_LIB_SSL, 296}, - #endif - #ifdef SSL_R_MISSING_DH_DSA_CERT - {"MISSING_DH_DSA_CERT", ERR_LIB_SSL, SSL_R_MISSING_DH_DSA_CERT}, - #else - {"MISSING_DH_DSA_CERT", ERR_LIB_SSL, 162}, - #endif - #ifdef SSL_R_MISSING_DH_KEY - {"MISSING_DH_KEY", ERR_LIB_SSL, SSL_R_MISSING_DH_KEY}, - #else - {"MISSING_DH_KEY", ERR_LIB_SSL, 163}, - #endif - #ifdef SSL_R_MISSING_DH_RSA_CERT - {"MISSING_DH_RSA_CERT", ERR_LIB_SSL, SSL_R_MISSING_DH_RSA_CERT}, - #else - {"MISSING_DH_RSA_CERT", ERR_LIB_SSL, 164}, - #endif - #ifdef SSL_R_MISSING_DSA_SIGNING_CERT - {"MISSING_DSA_SIGNING_CERT", ERR_LIB_SSL, SSL_R_MISSING_DSA_SIGNING_CERT}, - #else - {"MISSING_DSA_SIGNING_CERT", ERR_LIB_SSL, 165}, - #endif - #ifdef SSL_R_MISSING_ECDH_CERT - {"MISSING_ECDH_CERT", ERR_LIB_SSL, SSL_R_MISSING_ECDH_CERT}, - #else - {"MISSING_ECDH_CERT", ERR_LIB_SSL, 382}, - #endif - #ifdef SSL_R_MISSING_ECDSA_SIGNING_CERT - {"MISSING_ECDSA_SIGNING_CERT", ERR_LIB_SSL, SSL_R_MISSING_ECDSA_SIGNING_CERT}, - #else - {"MISSING_ECDSA_SIGNING_CERT", ERR_LIB_SSL, 381}, - #endif - #ifdef SSL_R_MISSING_EXPORT_TMP_DH_KEY - {"MISSING_EXPORT_TMP_DH_KEY", ERR_LIB_SSL, SSL_R_MISSING_EXPORT_TMP_DH_KEY}, - #else - {"MISSING_EXPORT_TMP_DH_KEY", ERR_LIB_SSL, 166}, - #endif - #ifdef SSL_R_MISSING_EXPORT_TMP_RSA_KEY - {"MISSING_EXPORT_TMP_RSA_KEY", ERR_LIB_SSL, SSL_R_MISSING_EXPORT_TMP_RSA_KEY}, - #else - {"MISSING_EXPORT_TMP_RSA_KEY", ERR_LIB_SSL, 167}, - #endif - #ifdef SSL_R_MISSING_RSA_CERTIFICATE - {"MISSING_RSA_CERTIFICATE", ERR_LIB_SSL, SSL_R_MISSING_RSA_CERTIFICATE}, - #else - {"MISSING_RSA_CERTIFICATE", ERR_LIB_SSL, 168}, - #endif - #ifdef SSL_R_MISSING_RSA_ENCRYPTING_CERT - {"MISSING_RSA_ENCRYPTING_CERT", ERR_LIB_SSL, SSL_R_MISSING_RSA_ENCRYPTING_CERT}, - #else - {"MISSING_RSA_ENCRYPTING_CERT", ERR_LIB_SSL, 169}, - #endif - #ifdef SSL_R_MISSING_RSA_SIGNING_CERT - {"MISSING_RSA_SIGNING_CERT", ERR_LIB_SSL, SSL_R_MISSING_RSA_SIGNING_CERT}, - #else - {"MISSING_RSA_SIGNING_CERT", ERR_LIB_SSL, 170}, - #endif - #ifdef SSL_R_MISSING_SRP_PARAM - {"MISSING_SRP_PARAM", ERR_LIB_SSL, SSL_R_MISSING_SRP_PARAM}, - #else - {"MISSING_SRP_PARAM", ERR_LIB_SSL, 358}, - #endif - #ifdef SSL_R_MISSING_TMP_DH_KEY - {"MISSING_TMP_DH_KEY", ERR_LIB_SSL, SSL_R_MISSING_TMP_DH_KEY}, - #else - {"MISSING_TMP_DH_KEY", ERR_LIB_SSL, 171}, - #endif - #ifdef SSL_R_MISSING_TMP_ECDH_KEY - {"MISSING_TMP_ECDH_KEY", ERR_LIB_SSL, SSL_R_MISSING_TMP_ECDH_KEY}, - #else - {"MISSING_TMP_ECDH_KEY", ERR_LIB_SSL, 311}, - #endif - #ifdef SSL_R_MISSING_TMP_RSA_KEY - {"MISSING_TMP_RSA_KEY", ERR_LIB_SSL, SSL_R_MISSING_TMP_RSA_KEY}, - #else - {"MISSING_TMP_RSA_KEY", ERR_LIB_SSL, 172}, - #endif - #ifdef SSL_R_MISSING_TMP_RSA_PKEY - {"MISSING_TMP_RSA_PKEY", ERR_LIB_SSL, SSL_R_MISSING_TMP_RSA_PKEY}, - #else - {"MISSING_TMP_RSA_PKEY", ERR_LIB_SSL, 173}, - #endif - #ifdef SSL_R_MISSING_VERIFY_MESSAGE - {"MISSING_VERIFY_MESSAGE", ERR_LIB_SSL, SSL_R_MISSING_VERIFY_MESSAGE}, - #else - {"MISSING_VERIFY_MESSAGE", ERR_LIB_SSL, 174}, - #endif - #ifdef SSL_R_MULTIPLE_SGC_RESTARTS - {"MULTIPLE_SGC_RESTARTS", ERR_LIB_SSL, SSL_R_MULTIPLE_SGC_RESTARTS}, - #else - {"MULTIPLE_SGC_RESTARTS", ERR_LIB_SSL, 346}, - #endif - #ifdef SSL_R_NON_SSLV2_INITIAL_PACKET - {"NON_SSLV2_INITIAL_PACKET", ERR_LIB_SSL, SSL_R_NON_SSLV2_INITIAL_PACKET}, - #else - {"NON_SSLV2_INITIAL_PACKET", ERR_LIB_SSL, 175}, - #endif - #ifdef SSL_R_NO_CERTIFICATES_RETURNED - {"NO_CERTIFICATES_RETURNED", ERR_LIB_SSL, SSL_R_NO_CERTIFICATES_RETURNED}, - #else - {"NO_CERTIFICATES_RETURNED", ERR_LIB_SSL, 176}, - #endif - #ifdef SSL_R_NO_CERTIFICATE_ASSIGNED - {"NO_CERTIFICATE_ASSIGNED", ERR_LIB_SSL, SSL_R_NO_CERTIFICATE_ASSIGNED}, - #else - {"NO_CERTIFICATE_ASSIGNED", ERR_LIB_SSL, 177}, - #endif - #ifdef SSL_R_NO_CERTIFICATE_RETURNED - {"NO_CERTIFICATE_RETURNED", ERR_LIB_SSL, SSL_R_NO_CERTIFICATE_RETURNED}, - #else - {"NO_CERTIFICATE_RETURNED", ERR_LIB_SSL, 178}, - #endif - #ifdef SSL_R_NO_CERTIFICATE_SET - {"NO_CERTIFICATE_SET", ERR_LIB_SSL, SSL_R_NO_CERTIFICATE_SET}, - #else - {"NO_CERTIFICATE_SET", ERR_LIB_SSL, 179}, - #endif - #ifdef SSL_R_NO_CERTIFICATE_SPECIFIED - {"NO_CERTIFICATE_SPECIFIED", ERR_LIB_SSL, SSL_R_NO_CERTIFICATE_SPECIFIED}, - #else - {"NO_CERTIFICATE_SPECIFIED", ERR_LIB_SSL, 180}, - #endif - #ifdef SSL_R_NO_CIPHERS_AVAILABLE - {"NO_CIPHERS_AVAILABLE", ERR_LIB_SSL, SSL_R_NO_CIPHERS_AVAILABLE}, - #else - {"NO_CIPHERS_AVAILABLE", ERR_LIB_SSL, 181}, - #endif - #ifdef SSL_R_NO_CIPHERS_PASSED - {"NO_CIPHERS_PASSED", ERR_LIB_SSL, SSL_R_NO_CIPHERS_PASSED}, - #else - {"NO_CIPHERS_PASSED", ERR_LIB_SSL, 182}, - #endif - #ifdef SSL_R_NO_CIPHERS_SPECIFIED - {"NO_CIPHERS_SPECIFIED", ERR_LIB_SSL, SSL_R_NO_CIPHERS_SPECIFIED}, - #else - {"NO_CIPHERS_SPECIFIED", ERR_LIB_SSL, 183}, - #endif - #ifdef SSL_R_NO_CIPHER_LIST - {"NO_CIPHER_LIST", ERR_LIB_SSL, SSL_R_NO_CIPHER_LIST}, - #else - {"NO_CIPHER_LIST", ERR_LIB_SSL, 184}, - #endif - #ifdef SSL_R_NO_CIPHER_MATCH - {"NO_CIPHER_MATCH", ERR_LIB_SSL, SSL_R_NO_CIPHER_MATCH}, - #else - {"NO_CIPHER_MATCH", ERR_LIB_SSL, 185}, - #endif - #ifdef SSL_R_NO_CLIENT_CERT_METHOD - {"NO_CLIENT_CERT_METHOD", ERR_LIB_SSL, SSL_R_NO_CLIENT_CERT_METHOD}, - #else - {"NO_CLIENT_CERT_METHOD", ERR_LIB_SSL, 331}, - #endif - #ifdef SSL_R_NO_CLIENT_CERT_RECEIVED - {"NO_CLIENT_CERT_RECEIVED", ERR_LIB_SSL, SSL_R_NO_CLIENT_CERT_RECEIVED}, - #else - {"NO_CLIENT_CERT_RECEIVED", ERR_LIB_SSL, 186}, - #endif - #ifdef SSL_R_NO_COMPRESSION_SPECIFIED - {"NO_COMPRESSION_SPECIFIED", ERR_LIB_SSL, SSL_R_NO_COMPRESSION_SPECIFIED}, - #else - {"NO_COMPRESSION_SPECIFIED", ERR_LIB_SSL, 187}, - #endif - #ifdef SSL_R_NO_GOST_CERTIFICATE_SENT_BY_PEER - {"NO_GOST_CERTIFICATE_SENT_BY_PEER", ERR_LIB_SSL, SSL_R_NO_GOST_CERTIFICATE_SENT_BY_PEER}, - #else - {"NO_GOST_CERTIFICATE_SENT_BY_PEER", ERR_LIB_SSL, 330}, - #endif - #ifdef SSL_R_NO_METHOD_SPECIFIED - {"NO_METHOD_SPECIFIED", ERR_LIB_SSL, SSL_R_NO_METHOD_SPECIFIED}, - #else - {"NO_METHOD_SPECIFIED", ERR_LIB_SSL, 188}, - #endif - #ifdef SSL_R_NO_PEM_EXTENSIONS - {"NO_PEM_EXTENSIONS", ERR_LIB_SSL, SSL_R_NO_PEM_EXTENSIONS}, - #else - {"NO_PEM_EXTENSIONS", ERR_LIB_SSL, 389}, - #endif - #ifdef SSL_R_NO_PRIVATEKEY - {"NO_PRIVATEKEY", ERR_LIB_SSL, SSL_R_NO_PRIVATEKEY}, - #else - {"NO_PRIVATEKEY", ERR_LIB_SSL, 189}, - #endif - #ifdef SSL_R_NO_PRIVATE_KEY_ASSIGNED - {"NO_PRIVATE_KEY_ASSIGNED", ERR_LIB_SSL, SSL_R_NO_PRIVATE_KEY_ASSIGNED}, - #else - {"NO_PRIVATE_KEY_ASSIGNED", ERR_LIB_SSL, 190}, - #endif - #ifdef SSL_R_NO_PROTOCOLS_AVAILABLE - {"NO_PROTOCOLS_AVAILABLE", ERR_LIB_SSL, SSL_R_NO_PROTOCOLS_AVAILABLE}, - #else - {"NO_PROTOCOLS_AVAILABLE", ERR_LIB_SSL, 191}, - #endif - #ifdef SSL_R_NO_PUBLICKEY - {"NO_PUBLICKEY", ERR_LIB_SSL, SSL_R_NO_PUBLICKEY}, - #else - {"NO_PUBLICKEY", ERR_LIB_SSL, 192}, - #endif - #ifdef SSL_R_NO_RENEGOTIATION - {"NO_RENEGOTIATION", ERR_LIB_SSL, SSL_R_NO_RENEGOTIATION}, - #else - {"NO_RENEGOTIATION", ERR_LIB_SSL, 339}, - #endif - #ifdef SSL_R_NO_REQUIRED_DIGEST - {"NO_REQUIRED_DIGEST", ERR_LIB_SSL, SSL_R_NO_REQUIRED_DIGEST}, - #else - {"NO_REQUIRED_DIGEST", ERR_LIB_SSL, 324}, - #endif - #ifdef SSL_R_NO_SHARED_CIPHER - {"NO_SHARED_CIPHER", ERR_LIB_SSL, SSL_R_NO_SHARED_CIPHER}, - #else - {"NO_SHARED_CIPHER", ERR_LIB_SSL, 193}, - #endif - #ifdef SSL_R_NO_SHARED_SIGATURE_ALGORITHMS - {"NO_SHARED_SIGATURE_ALGORITHMS", ERR_LIB_SSL, SSL_R_NO_SHARED_SIGATURE_ALGORITHMS}, - #else - {"NO_SHARED_SIGATURE_ALGORITHMS", ERR_LIB_SSL, 376}, - #endif - #ifdef SSL_R_NO_SRTP_PROFILES - {"NO_SRTP_PROFILES", ERR_LIB_SSL, SSL_R_NO_SRTP_PROFILES}, - #else - {"NO_SRTP_PROFILES", ERR_LIB_SSL, 359}, - #endif - #ifdef SSL_R_NO_VERIFY_CALLBACK - {"NO_VERIFY_CALLBACK", ERR_LIB_SSL, SSL_R_NO_VERIFY_CALLBACK}, - #else - {"NO_VERIFY_CALLBACK", ERR_LIB_SSL, 194}, - #endif - #ifdef SSL_R_NULL_SSL_CTX - {"NULL_SSL_CTX", ERR_LIB_SSL, SSL_R_NULL_SSL_CTX}, - #else - {"NULL_SSL_CTX", ERR_LIB_SSL, 195}, - #endif - #ifdef SSL_R_NULL_SSL_METHOD_PASSED - {"NULL_SSL_METHOD_PASSED", ERR_LIB_SSL, SSL_R_NULL_SSL_METHOD_PASSED}, - #else - {"NULL_SSL_METHOD_PASSED", ERR_LIB_SSL, 196}, - #endif - #ifdef SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED - {"OLD_SESSION_CIPHER_NOT_RETURNED", ERR_LIB_SSL, SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED}, - #else - {"OLD_SESSION_CIPHER_NOT_RETURNED", ERR_LIB_SSL, 197}, - #endif - #ifdef SSL_R_OLD_SESSION_COMPRESSION_ALGORITHM_NOT_RETURNED - {"OLD_SESSION_COMPRESSION_ALGORITHM_NOT_RETURNED", ERR_LIB_SSL, SSL_R_OLD_SESSION_COMPRESSION_ALGORITHM_NOT_RETURNED}, - #else - {"OLD_SESSION_COMPRESSION_ALGORITHM_NOT_RETURNED", ERR_LIB_SSL, 344}, - #endif - #ifdef SSL_R_ONLY_DTLS_1_2_ALLOWED_IN_SUITEB_MODE - {"ONLY_DTLS_1_2_ALLOWED_IN_SUITEB_MODE", ERR_LIB_SSL, SSL_R_ONLY_DTLS_1_2_ALLOWED_IN_SUITEB_MODE}, - #else - {"ONLY_DTLS_1_2_ALLOWED_IN_SUITEB_MODE", ERR_LIB_SSL, 387}, - #endif - #ifdef SSL_R_ONLY_TLS_1_2_ALLOWED_IN_SUITEB_MODE - {"ONLY_TLS_1_2_ALLOWED_IN_SUITEB_MODE", ERR_LIB_SSL, SSL_R_ONLY_TLS_1_2_ALLOWED_IN_SUITEB_MODE}, - #else - {"ONLY_TLS_1_2_ALLOWED_IN_SUITEB_MODE", ERR_LIB_SSL, 379}, - #endif - #ifdef SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE - {"ONLY_TLS_ALLOWED_IN_FIPS_MODE", ERR_LIB_SSL, SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE}, - #else - {"ONLY_TLS_ALLOWED_IN_FIPS_MODE", ERR_LIB_SSL, 297}, - #endif - #ifdef SSL_R_OPAQUE_PRF_INPUT_TOO_LONG - {"OPAQUE_PRF_INPUT_TOO_LONG", ERR_LIB_SSL, SSL_R_OPAQUE_PRF_INPUT_TOO_LONG}, - #else - {"OPAQUE_PRF_INPUT_TOO_LONG", ERR_LIB_SSL, 327}, - #endif - #ifdef SSL_R_PACKET_LENGTH_TOO_LONG - {"PACKET_LENGTH_TOO_LONG", ERR_LIB_SSL, SSL_R_PACKET_LENGTH_TOO_LONG}, - #else - {"PACKET_LENGTH_TOO_LONG", ERR_LIB_SSL, 198}, - #endif - #ifdef SSL_R_PARSE_TLSEXT - {"PARSE_TLSEXT", ERR_LIB_SSL, SSL_R_PARSE_TLSEXT}, - #else - {"PARSE_TLSEXT", ERR_LIB_SSL, 227}, - #endif - #ifdef SSL_R_PATH_TOO_LONG - {"PATH_TOO_LONG", ERR_LIB_SSL, SSL_R_PATH_TOO_LONG}, - #else - {"PATH_TOO_LONG", ERR_LIB_SSL, 270}, - #endif - #ifdef SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE - {"PEER_DID_NOT_RETURN_A_CERTIFICATE", ERR_LIB_SSL, SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE}, - #else - {"PEER_DID_NOT_RETURN_A_CERTIFICATE", ERR_LIB_SSL, 199}, - #endif - #ifdef SSL_R_PEER_ERROR - {"PEER_ERROR", ERR_LIB_SSL, SSL_R_PEER_ERROR}, - #else - {"PEER_ERROR", ERR_LIB_SSL, 200}, - #endif - #ifdef SSL_R_PEER_ERROR_CERTIFICATE - {"PEER_ERROR_CERTIFICATE", ERR_LIB_SSL, SSL_R_PEER_ERROR_CERTIFICATE}, - #else - {"PEER_ERROR_CERTIFICATE", ERR_LIB_SSL, 201}, - #endif - #ifdef SSL_R_PEER_ERROR_NO_CERTIFICATE - {"PEER_ERROR_NO_CERTIFICATE", ERR_LIB_SSL, SSL_R_PEER_ERROR_NO_CERTIFICATE}, - #else - {"PEER_ERROR_NO_CERTIFICATE", ERR_LIB_SSL, 202}, - #endif - #ifdef SSL_R_PEER_ERROR_NO_CIPHER - {"PEER_ERROR_NO_CIPHER", ERR_LIB_SSL, SSL_R_PEER_ERROR_NO_CIPHER}, - #else - {"PEER_ERROR_NO_CIPHER", ERR_LIB_SSL, 203}, - #endif - #ifdef SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE - {"PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE", ERR_LIB_SSL, SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE}, - #else - {"PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE", ERR_LIB_SSL, 204}, - #endif - #ifdef SSL_R_PEM_NAME_BAD_PREFIX - {"PEM_NAME_BAD_PREFIX", ERR_LIB_SSL, SSL_R_PEM_NAME_BAD_PREFIX}, - #else - {"PEM_NAME_BAD_PREFIX", ERR_LIB_SSL, 391}, - #endif - #ifdef SSL_R_PEM_NAME_TOO_SHORT - {"PEM_NAME_TOO_SHORT", ERR_LIB_SSL, SSL_R_PEM_NAME_TOO_SHORT}, - #else - {"PEM_NAME_TOO_SHORT", ERR_LIB_SSL, 392}, - #endif - #ifdef SSL_R_PRE_MAC_LENGTH_TOO_LONG - {"PRE_MAC_LENGTH_TOO_LONG", ERR_LIB_SSL, SSL_R_PRE_MAC_LENGTH_TOO_LONG}, - #else - {"PRE_MAC_LENGTH_TOO_LONG", ERR_LIB_SSL, 205}, - #endif - #ifdef SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS - {"PROBLEMS_MAPPING_CIPHER_FUNCTIONS", ERR_LIB_SSL, SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS}, - #else - {"PROBLEMS_MAPPING_CIPHER_FUNCTIONS", ERR_LIB_SSL, 206}, - #endif - #ifdef SSL_R_PROTOCOL_IS_SHUTDOWN - {"PROTOCOL_IS_SHUTDOWN", ERR_LIB_SSL, SSL_R_PROTOCOL_IS_SHUTDOWN}, - #else - {"PROTOCOL_IS_SHUTDOWN", ERR_LIB_SSL, 207}, - #endif - #ifdef SSL_R_PSK_IDENTITY_NOT_FOUND - {"PSK_IDENTITY_NOT_FOUND", ERR_LIB_SSL, SSL_R_PSK_IDENTITY_NOT_FOUND}, - #else - {"PSK_IDENTITY_NOT_FOUND", ERR_LIB_SSL, 223}, - #endif - #ifdef SSL_R_PSK_NO_CLIENT_CB - {"PSK_NO_CLIENT_CB", ERR_LIB_SSL, SSL_R_PSK_NO_CLIENT_CB}, - #else - {"PSK_NO_CLIENT_CB", ERR_LIB_SSL, 224}, - #endif - #ifdef SSL_R_PSK_NO_SERVER_CB - {"PSK_NO_SERVER_CB", ERR_LIB_SSL, SSL_R_PSK_NO_SERVER_CB}, - #else - {"PSK_NO_SERVER_CB", ERR_LIB_SSL, 225}, - #endif - #ifdef SSL_R_PUBLIC_KEY_ENCRYPT_ERROR - {"PUBLIC_KEY_ENCRYPT_ERROR", ERR_LIB_SSL, SSL_R_PUBLIC_KEY_ENCRYPT_ERROR}, - #else - {"PUBLIC_KEY_ENCRYPT_ERROR", ERR_LIB_SSL, 208}, - #endif - #ifdef SSL_R_PUBLIC_KEY_IS_NOT_RSA - {"PUBLIC_KEY_IS_NOT_RSA", ERR_LIB_SSL, SSL_R_PUBLIC_KEY_IS_NOT_RSA}, - #else - {"PUBLIC_KEY_IS_NOT_RSA", ERR_LIB_SSL, 209}, - #endif - #ifdef SSL_R_PUBLIC_KEY_NOT_RSA - {"PUBLIC_KEY_NOT_RSA", ERR_LIB_SSL, SSL_R_PUBLIC_KEY_NOT_RSA}, - #else - {"PUBLIC_KEY_NOT_RSA", ERR_LIB_SSL, 210}, - #endif - #ifdef SSL_R_READ_BIO_NOT_SET - {"READ_BIO_NOT_SET", ERR_LIB_SSL, SSL_R_READ_BIO_NOT_SET}, - #else - {"READ_BIO_NOT_SET", ERR_LIB_SSL, 211}, - #endif - #ifdef SSL_R_READ_TIMEOUT_EXPIRED - {"READ_TIMEOUT_EXPIRED", ERR_LIB_SSL, SSL_R_READ_TIMEOUT_EXPIRED}, - #else - {"READ_TIMEOUT_EXPIRED", ERR_LIB_SSL, 312}, - #endif - #ifdef SSL_R_READ_WRONG_PACKET_TYPE - {"READ_WRONG_PACKET_TYPE", ERR_LIB_SSL, SSL_R_READ_WRONG_PACKET_TYPE}, - #else - {"READ_WRONG_PACKET_TYPE", ERR_LIB_SSL, 212}, - #endif - #ifdef SSL_R_RECORD_LENGTH_MISMATCH - {"RECORD_LENGTH_MISMATCH", ERR_LIB_SSL, SSL_R_RECORD_LENGTH_MISMATCH}, - #else - {"RECORD_LENGTH_MISMATCH", ERR_LIB_SSL, 213}, - #endif - #ifdef SSL_R_RECORD_TOO_LARGE - {"RECORD_TOO_LARGE", ERR_LIB_SSL, SSL_R_RECORD_TOO_LARGE}, - #else - {"RECORD_TOO_LARGE", ERR_LIB_SSL, 214}, - #endif - #ifdef SSL_R_RECORD_TOO_SMALL - {"RECORD_TOO_SMALL", ERR_LIB_SSL, SSL_R_RECORD_TOO_SMALL}, - #else - {"RECORD_TOO_SMALL", ERR_LIB_SSL, 298}, - #endif - #ifdef SSL_R_RENEGOTIATE_EXT_TOO_LONG - {"RENEGOTIATE_EXT_TOO_LONG", ERR_LIB_SSL, SSL_R_RENEGOTIATE_EXT_TOO_LONG}, - #else - {"RENEGOTIATE_EXT_TOO_LONG", ERR_LIB_SSL, 335}, - #endif - #ifdef SSL_R_RENEGOTIATION_ENCODING_ERR - {"RENEGOTIATION_ENCODING_ERR", ERR_LIB_SSL, SSL_R_RENEGOTIATION_ENCODING_ERR}, - #else - {"RENEGOTIATION_ENCODING_ERR", ERR_LIB_SSL, 336}, - #endif - #ifdef SSL_R_RENEGOTIATION_MISMATCH - {"RENEGOTIATION_MISMATCH", ERR_LIB_SSL, SSL_R_RENEGOTIATION_MISMATCH}, - #else - {"RENEGOTIATION_MISMATCH", ERR_LIB_SSL, 337}, - #endif - #ifdef SSL_R_REQUIRED_CIPHER_MISSING - {"REQUIRED_CIPHER_MISSING", ERR_LIB_SSL, SSL_R_REQUIRED_CIPHER_MISSING}, - #else - {"REQUIRED_CIPHER_MISSING", ERR_LIB_SSL, 215}, - #endif - #ifdef SSL_R_REQUIRED_COMPRESSSION_ALGORITHM_MISSING - {"REQUIRED_COMPRESSSION_ALGORITHM_MISSING", ERR_LIB_SSL, SSL_R_REQUIRED_COMPRESSSION_ALGORITHM_MISSING}, - #else - {"REQUIRED_COMPRESSSION_ALGORITHM_MISSING", ERR_LIB_SSL, 342}, - #endif - #ifdef SSL_R_REUSE_CERT_LENGTH_NOT_ZERO - {"REUSE_CERT_LENGTH_NOT_ZERO", ERR_LIB_SSL, SSL_R_REUSE_CERT_LENGTH_NOT_ZERO}, - #else - {"REUSE_CERT_LENGTH_NOT_ZERO", ERR_LIB_SSL, 216}, - #endif - #ifdef SSL_R_REUSE_CERT_TYPE_NOT_ZERO - {"REUSE_CERT_TYPE_NOT_ZERO", ERR_LIB_SSL, SSL_R_REUSE_CERT_TYPE_NOT_ZERO}, - #else - {"REUSE_CERT_TYPE_NOT_ZERO", ERR_LIB_SSL, 217}, - #endif - #ifdef SSL_R_REUSE_CIPHER_LIST_NOT_ZERO - {"REUSE_CIPHER_LIST_NOT_ZERO", ERR_LIB_SSL, SSL_R_REUSE_CIPHER_LIST_NOT_ZERO}, - #else - {"REUSE_CIPHER_LIST_NOT_ZERO", ERR_LIB_SSL, 218}, - #endif - #ifdef SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING - {"SCSV_RECEIVED_WHEN_RENEGOTIATING", ERR_LIB_SSL, SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING}, - #else - {"SCSV_RECEIVED_WHEN_RENEGOTIATING", ERR_LIB_SSL, 345}, - #endif - #ifdef SSL_R_SERVERHELLO_TLSEXT - {"SERVERHELLO_TLSEXT", ERR_LIB_SSL, SSL_R_SERVERHELLO_TLSEXT}, - #else - {"SERVERHELLO_TLSEXT", ERR_LIB_SSL, 275}, - #endif - #ifdef SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED - {"SESSION_ID_CONTEXT_UNINITIALIZED", ERR_LIB_SSL, SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED}, - #else - {"SESSION_ID_CONTEXT_UNINITIALIZED", ERR_LIB_SSL, 277}, - #endif - #ifdef SSL_R_SHORT_READ - {"SHORT_READ", ERR_LIB_SSL, SSL_R_SHORT_READ}, - #else - {"SHORT_READ", ERR_LIB_SSL, 219}, - #endif - #ifdef SSL_R_SIGNATURE_ALGORITHMS_ERROR - {"SIGNATURE_ALGORITHMS_ERROR", ERR_LIB_SSL, SSL_R_SIGNATURE_ALGORITHMS_ERROR}, - #else - {"SIGNATURE_ALGORITHMS_ERROR", ERR_LIB_SSL, 360}, - #endif - #ifdef SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE - {"SIGNATURE_FOR_NON_SIGNING_CERTIFICATE", ERR_LIB_SSL, SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE}, - #else - {"SIGNATURE_FOR_NON_SIGNING_CERTIFICATE", ERR_LIB_SSL, 220}, - #endif - #ifdef SSL_R_SRP_A_CALC - {"SRP_A_CALC", ERR_LIB_SSL, SSL_R_SRP_A_CALC}, - #else - {"SRP_A_CALC", ERR_LIB_SSL, 361}, - #endif - #ifdef SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES - {"SRTP_COULD_NOT_ALLOCATE_PROFILES", ERR_LIB_SSL, SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES}, - #else - {"SRTP_COULD_NOT_ALLOCATE_PROFILES", ERR_LIB_SSL, 362}, - #endif - #ifdef SSL_R_SRTP_PROTECTION_PROFILE_LIST_TOO_LONG - {"SRTP_PROTECTION_PROFILE_LIST_TOO_LONG", ERR_LIB_SSL, SSL_R_SRTP_PROTECTION_PROFILE_LIST_TOO_LONG}, - #else - {"SRTP_PROTECTION_PROFILE_LIST_TOO_LONG", ERR_LIB_SSL, 363}, - #endif - #ifdef SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE - {"SRTP_UNKNOWN_PROTECTION_PROFILE", ERR_LIB_SSL, SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE}, - #else - {"SRTP_UNKNOWN_PROTECTION_PROFILE", ERR_LIB_SSL, 364}, - #endif - #ifdef SSL_R_SSL23_DOING_SESSION_ID_REUSE - {"SSL23_DOING_SESSION_ID_REUSE", ERR_LIB_SSL, SSL_R_SSL23_DOING_SESSION_ID_REUSE}, - #else - {"SSL23_DOING_SESSION_ID_REUSE", ERR_LIB_SSL, 221}, - #endif - #ifdef SSL_R_SSL2_CONNECTION_ID_TOO_LONG - {"SSL2_CONNECTION_ID_TOO_LONG", ERR_LIB_SSL, SSL_R_SSL2_CONNECTION_ID_TOO_LONG}, - #else - {"SSL2_CONNECTION_ID_TOO_LONG", ERR_LIB_SSL, 299}, - #endif - #ifdef SSL_R_SSL3_EXT_INVALID_ECPOINTFORMAT - {"SSL3_EXT_INVALID_ECPOINTFORMAT", ERR_LIB_SSL, SSL_R_SSL3_EXT_INVALID_ECPOINTFORMAT}, - #else - {"SSL3_EXT_INVALID_ECPOINTFORMAT", ERR_LIB_SSL, 321}, - #endif - #ifdef SSL_R_SSL3_EXT_INVALID_SERVERNAME - {"SSL3_EXT_INVALID_SERVERNAME", ERR_LIB_SSL, SSL_R_SSL3_EXT_INVALID_SERVERNAME}, - #else - {"SSL3_EXT_INVALID_SERVERNAME", ERR_LIB_SSL, 319}, - #endif - #ifdef SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE - {"SSL3_EXT_INVALID_SERVERNAME_TYPE", ERR_LIB_SSL, SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE}, - #else - {"SSL3_EXT_INVALID_SERVERNAME_TYPE", ERR_LIB_SSL, 320}, - #endif - #ifdef SSL_R_SSL3_SESSION_ID_TOO_LONG - {"SSL3_SESSION_ID_TOO_LONG", ERR_LIB_SSL, SSL_R_SSL3_SESSION_ID_TOO_LONG}, - #else - {"SSL3_SESSION_ID_TOO_LONG", ERR_LIB_SSL, 300}, - #endif - #ifdef SSL_R_SSL3_SESSION_ID_TOO_SHORT - {"SSL3_SESSION_ID_TOO_SHORT", ERR_LIB_SSL, SSL_R_SSL3_SESSION_ID_TOO_SHORT}, - #else - {"SSL3_SESSION_ID_TOO_SHORT", ERR_LIB_SSL, 222}, - #endif - #ifdef SSL_R_SSLV3_ALERT_BAD_CERTIFICATE - {"SSLV3_ALERT_BAD_CERTIFICATE", ERR_LIB_SSL, SSL_R_SSLV3_ALERT_BAD_CERTIFICATE}, - #else - {"SSLV3_ALERT_BAD_CERTIFICATE", ERR_LIB_SSL, 1042}, - #endif - #ifdef SSL_R_SSLV3_ALERT_BAD_RECORD_MAC - {"SSLV3_ALERT_BAD_RECORD_MAC", ERR_LIB_SSL, SSL_R_SSLV3_ALERT_BAD_RECORD_MAC}, - #else - {"SSLV3_ALERT_BAD_RECORD_MAC", ERR_LIB_SSL, 1020}, - #endif - #ifdef SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED - {"SSLV3_ALERT_CERTIFICATE_EXPIRED", ERR_LIB_SSL, SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED}, - #else - {"SSLV3_ALERT_CERTIFICATE_EXPIRED", ERR_LIB_SSL, 1045}, - #endif - #ifdef SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED - {"SSLV3_ALERT_CERTIFICATE_REVOKED", ERR_LIB_SSL, SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED}, - #else - {"SSLV3_ALERT_CERTIFICATE_REVOKED", ERR_LIB_SSL, 1044}, - #endif - #ifdef SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN - {"SSLV3_ALERT_CERTIFICATE_UNKNOWN", ERR_LIB_SSL, SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN}, - #else - {"SSLV3_ALERT_CERTIFICATE_UNKNOWN", ERR_LIB_SSL, 1046}, - #endif - #ifdef SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE - {"SSLV3_ALERT_DECOMPRESSION_FAILURE", ERR_LIB_SSL, SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE}, - #else - {"SSLV3_ALERT_DECOMPRESSION_FAILURE", ERR_LIB_SSL, 1030}, - #endif - #ifdef SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE - {"SSLV3_ALERT_HANDSHAKE_FAILURE", ERR_LIB_SSL, SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE}, - #else - {"SSLV3_ALERT_HANDSHAKE_FAILURE", ERR_LIB_SSL, 1040}, - #endif - #ifdef SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER - {"SSLV3_ALERT_ILLEGAL_PARAMETER", ERR_LIB_SSL, SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER}, - #else - {"SSLV3_ALERT_ILLEGAL_PARAMETER", ERR_LIB_SSL, 1047}, - #endif - #ifdef SSL_R_SSLV3_ALERT_NO_CERTIFICATE - {"SSLV3_ALERT_NO_CERTIFICATE", ERR_LIB_SSL, SSL_R_SSLV3_ALERT_NO_CERTIFICATE}, - #else - {"SSLV3_ALERT_NO_CERTIFICATE", ERR_LIB_SSL, 1041}, - #endif - #ifdef SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE - {"SSLV3_ALERT_UNEXPECTED_MESSAGE", ERR_LIB_SSL, SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE}, - #else - {"SSLV3_ALERT_UNEXPECTED_MESSAGE", ERR_LIB_SSL, 1010}, - #endif - #ifdef SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE - {"SSLV3_ALERT_UNSUPPORTED_CERTIFICATE", ERR_LIB_SSL, SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE}, - #else - {"SSLV3_ALERT_UNSUPPORTED_CERTIFICATE", ERR_LIB_SSL, 1043}, - #endif - #ifdef SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION - {"SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION", ERR_LIB_SSL, SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION}, - #else - {"SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION", ERR_LIB_SSL, 228}, - #endif - #ifdef SSL_R_SSL_HANDSHAKE_FAILURE - {"SSL_HANDSHAKE_FAILURE", ERR_LIB_SSL, SSL_R_SSL_HANDSHAKE_FAILURE}, - #else - {"SSL_HANDSHAKE_FAILURE", ERR_LIB_SSL, 229}, - #endif - #ifdef SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS - {"SSL_LIBRARY_HAS_NO_CIPHERS", ERR_LIB_SSL, SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS}, - #else - {"SSL_LIBRARY_HAS_NO_CIPHERS", ERR_LIB_SSL, 230}, - #endif - #ifdef SSL_R_SSL_NEGATIVE_LENGTH - {"SSL_NEGATIVE_LENGTH", ERR_LIB_SSL, SSL_R_SSL_NEGATIVE_LENGTH}, - #else - {"SSL_NEGATIVE_LENGTH", ERR_LIB_SSL, 372}, - #endif - #ifdef SSL_R_SSL_SESSION_ID_CALLBACK_FAILED - {"SSL_SESSION_ID_CALLBACK_FAILED", ERR_LIB_SSL, SSL_R_SSL_SESSION_ID_CALLBACK_FAILED}, - #else - {"SSL_SESSION_ID_CALLBACK_FAILED", ERR_LIB_SSL, 301}, - #endif - #ifdef SSL_R_SSL_SESSION_ID_CONFLICT - {"SSL_SESSION_ID_CONFLICT", ERR_LIB_SSL, SSL_R_SSL_SESSION_ID_CONFLICT}, - #else - {"SSL_SESSION_ID_CONFLICT", ERR_LIB_SSL, 302}, - #endif - #ifdef SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG - {"SSL_SESSION_ID_CONTEXT_TOO_LONG", ERR_LIB_SSL, SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG}, - #else - {"SSL_SESSION_ID_CONTEXT_TOO_LONG", ERR_LIB_SSL, 273}, - #endif - #ifdef SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH - {"SSL_SESSION_ID_HAS_BAD_LENGTH", ERR_LIB_SSL, SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH}, - #else - {"SSL_SESSION_ID_HAS_BAD_LENGTH", ERR_LIB_SSL, 303}, - #endif - #ifdef SSL_R_SSL_SESSION_ID_IS_DIFFERENT - {"SSL_SESSION_ID_IS_DIFFERENT", ERR_LIB_SSL, SSL_R_SSL_SESSION_ID_IS_DIFFERENT}, - #else - {"SSL_SESSION_ID_IS_DIFFERENT", ERR_LIB_SSL, 231}, - #endif - #ifdef SSL_R_TLSV1_ALERT_ACCESS_DENIED - {"TLSV1_ALERT_ACCESS_DENIED", ERR_LIB_SSL, SSL_R_TLSV1_ALERT_ACCESS_DENIED}, - #else - {"TLSV1_ALERT_ACCESS_DENIED", ERR_LIB_SSL, 1049}, - #endif - #ifdef SSL_R_TLSV1_ALERT_DECODE_ERROR - {"TLSV1_ALERT_DECODE_ERROR", ERR_LIB_SSL, SSL_R_TLSV1_ALERT_DECODE_ERROR}, - #else - {"TLSV1_ALERT_DECODE_ERROR", ERR_LIB_SSL, 1050}, - #endif - #ifdef SSL_R_TLSV1_ALERT_DECRYPTION_FAILED - {"TLSV1_ALERT_DECRYPTION_FAILED", ERR_LIB_SSL, SSL_R_TLSV1_ALERT_DECRYPTION_FAILED}, - #else - {"TLSV1_ALERT_DECRYPTION_FAILED", ERR_LIB_SSL, 1021}, - #endif - #ifdef SSL_R_TLSV1_ALERT_DECRYPT_ERROR - {"TLSV1_ALERT_DECRYPT_ERROR", ERR_LIB_SSL, SSL_R_TLSV1_ALERT_DECRYPT_ERROR}, - #else - {"TLSV1_ALERT_DECRYPT_ERROR", ERR_LIB_SSL, 1051}, - #endif - #ifdef SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION - {"TLSV1_ALERT_EXPORT_RESTRICTION", ERR_LIB_SSL, SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION}, - #else - {"TLSV1_ALERT_EXPORT_RESTRICTION", ERR_LIB_SSL, 1060}, - #endif - #ifdef SSL_R_TLSV1_ALERT_INAPPROPRIATE_FALLBACK - {"TLSV1_ALERT_INAPPROPRIATE_FALLBACK", ERR_LIB_SSL, SSL_R_TLSV1_ALERT_INAPPROPRIATE_FALLBACK}, - #else - {"TLSV1_ALERT_INAPPROPRIATE_FALLBACK", ERR_LIB_SSL, 1086}, - #endif - #ifdef SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY - {"TLSV1_ALERT_INSUFFICIENT_SECURITY", ERR_LIB_SSL, SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY}, - #else - {"TLSV1_ALERT_INSUFFICIENT_SECURITY", ERR_LIB_SSL, 1071}, - #endif - #ifdef SSL_R_TLSV1_ALERT_INTERNAL_ERROR - {"TLSV1_ALERT_INTERNAL_ERROR", ERR_LIB_SSL, SSL_R_TLSV1_ALERT_INTERNAL_ERROR}, - #else - {"TLSV1_ALERT_INTERNAL_ERROR", ERR_LIB_SSL, 1080}, - #endif - #ifdef SSL_R_TLSV1_ALERT_NO_RENEGOTIATION - {"TLSV1_ALERT_NO_RENEGOTIATION", ERR_LIB_SSL, SSL_R_TLSV1_ALERT_NO_RENEGOTIATION}, - #else - {"TLSV1_ALERT_NO_RENEGOTIATION", ERR_LIB_SSL, 1100}, - #endif - #ifdef SSL_R_TLSV1_ALERT_PROTOCOL_VERSION - {"TLSV1_ALERT_PROTOCOL_VERSION", ERR_LIB_SSL, SSL_R_TLSV1_ALERT_PROTOCOL_VERSION}, - #else - {"TLSV1_ALERT_PROTOCOL_VERSION", ERR_LIB_SSL, 1070}, - #endif - #ifdef SSL_R_TLSV1_ALERT_RECORD_OVERFLOW - {"TLSV1_ALERT_RECORD_OVERFLOW", ERR_LIB_SSL, SSL_R_TLSV1_ALERT_RECORD_OVERFLOW}, - #else - {"TLSV1_ALERT_RECORD_OVERFLOW", ERR_LIB_SSL, 1022}, - #endif - #ifdef SSL_R_TLSV1_ALERT_UNKNOWN_CA - {"TLSV1_ALERT_UNKNOWN_CA", ERR_LIB_SSL, SSL_R_TLSV1_ALERT_UNKNOWN_CA}, - #else - {"TLSV1_ALERT_UNKNOWN_CA", ERR_LIB_SSL, 1048}, - #endif - #ifdef SSL_R_TLSV1_ALERT_USER_CANCELLED - {"TLSV1_ALERT_USER_CANCELLED", ERR_LIB_SSL, SSL_R_TLSV1_ALERT_USER_CANCELLED}, - #else - {"TLSV1_ALERT_USER_CANCELLED", ERR_LIB_SSL, 1090}, - #endif - #ifdef SSL_R_TLSV1_BAD_CERTIFICATE_HASH_VALUE - {"TLSV1_BAD_CERTIFICATE_HASH_VALUE", ERR_LIB_SSL, SSL_R_TLSV1_BAD_CERTIFICATE_HASH_VALUE}, - #else - {"TLSV1_BAD_CERTIFICATE_HASH_VALUE", ERR_LIB_SSL, 1114}, - #endif - #ifdef SSL_R_TLSV1_BAD_CERTIFICATE_STATUS_RESPONSE - {"TLSV1_BAD_CERTIFICATE_STATUS_RESPONSE", ERR_LIB_SSL, SSL_R_TLSV1_BAD_CERTIFICATE_STATUS_RESPONSE}, - #else - {"TLSV1_BAD_CERTIFICATE_STATUS_RESPONSE", ERR_LIB_SSL, 1113}, - #endif - #ifdef SSL_R_TLSV1_CERTIFICATE_UNOBTAINABLE - {"TLSV1_CERTIFICATE_UNOBTAINABLE", ERR_LIB_SSL, SSL_R_TLSV1_CERTIFICATE_UNOBTAINABLE}, - #else - {"TLSV1_CERTIFICATE_UNOBTAINABLE", ERR_LIB_SSL, 1111}, - #endif - #ifdef SSL_R_TLSV1_UNRECOGNIZED_NAME - {"TLSV1_UNRECOGNIZED_NAME", ERR_LIB_SSL, SSL_R_TLSV1_UNRECOGNIZED_NAME}, - #else - {"TLSV1_UNRECOGNIZED_NAME", ERR_LIB_SSL, 1112}, - #endif - #ifdef SSL_R_TLSV1_UNSUPPORTED_EXTENSION - {"TLSV1_UNSUPPORTED_EXTENSION", ERR_LIB_SSL, SSL_R_TLSV1_UNSUPPORTED_EXTENSION}, - #else - {"TLSV1_UNSUPPORTED_EXTENSION", ERR_LIB_SSL, 1110}, - #endif - #ifdef SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER - {"TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER", ERR_LIB_SSL, SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER}, - #else - {"TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER", ERR_LIB_SSL, 232}, - #endif - #ifdef SSL_R_TLS_HEARTBEAT_PEER_DOESNT_ACCEPT - {"TLS_HEARTBEAT_PEER_DOESNT_ACCEPT", ERR_LIB_SSL, SSL_R_TLS_HEARTBEAT_PEER_DOESNT_ACCEPT}, - #else - {"TLS_HEARTBEAT_PEER_DOESNT_ACCEPT", ERR_LIB_SSL, 365}, - #endif - #ifdef SSL_R_TLS_HEARTBEAT_PENDING - {"TLS_HEARTBEAT_PENDING", ERR_LIB_SSL, SSL_R_TLS_HEARTBEAT_PENDING}, - #else - {"TLS_HEARTBEAT_PENDING", ERR_LIB_SSL, 366}, - #endif - #ifdef SSL_R_TLS_ILLEGAL_EXPORTER_LABEL - {"TLS_ILLEGAL_EXPORTER_LABEL", ERR_LIB_SSL, SSL_R_TLS_ILLEGAL_EXPORTER_LABEL}, - #else - {"TLS_ILLEGAL_EXPORTER_LABEL", ERR_LIB_SSL, 367}, - #endif - #ifdef SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST - {"TLS_INVALID_ECPOINTFORMAT_LIST", ERR_LIB_SSL, SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST}, - #else - {"TLS_INVALID_ECPOINTFORMAT_LIST", ERR_LIB_SSL, 157}, - #endif - #ifdef SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST - {"TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST", ERR_LIB_SSL, SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST}, - #else - {"TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST", ERR_LIB_SSL, 233}, - #endif - #ifdef SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG - {"TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG", ERR_LIB_SSL, SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG}, - #else - {"TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG", ERR_LIB_SSL, 234}, - #endif - #ifdef SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER - {"TRIED_TO_USE_UNSUPPORTED_CIPHER", ERR_LIB_SSL, SSL_R_TRIED_TO_USE_UNSUPPORTED_CIPHER}, - #else - {"TRIED_TO_USE_UNSUPPORTED_CIPHER", ERR_LIB_SSL, 235}, - #endif - #ifdef SSL_R_UNABLE_TO_DECODE_DH_CERTS - {"UNABLE_TO_DECODE_DH_CERTS", ERR_LIB_SSL, SSL_R_UNABLE_TO_DECODE_DH_CERTS}, - #else - {"UNABLE_TO_DECODE_DH_CERTS", ERR_LIB_SSL, 236}, - #endif - #ifdef SSL_R_UNABLE_TO_DECODE_ECDH_CERTS - {"UNABLE_TO_DECODE_ECDH_CERTS", ERR_LIB_SSL, SSL_R_UNABLE_TO_DECODE_ECDH_CERTS}, - #else - {"UNABLE_TO_DECODE_ECDH_CERTS", ERR_LIB_SSL, 313}, - #endif - #ifdef SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY - {"UNABLE_TO_EXTRACT_PUBLIC_KEY", ERR_LIB_SSL, SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY}, - #else - {"UNABLE_TO_EXTRACT_PUBLIC_KEY", ERR_LIB_SSL, 237}, - #endif - #ifdef SSL_R_UNABLE_TO_FIND_DH_PARAMETERS - {"UNABLE_TO_FIND_DH_PARAMETERS", ERR_LIB_SSL, SSL_R_UNABLE_TO_FIND_DH_PARAMETERS}, - #else - {"UNABLE_TO_FIND_DH_PARAMETERS", ERR_LIB_SSL, 238}, - #endif - #ifdef SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS - {"UNABLE_TO_FIND_ECDH_PARAMETERS", ERR_LIB_SSL, SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS}, - #else - {"UNABLE_TO_FIND_ECDH_PARAMETERS", ERR_LIB_SSL, 314}, - #endif - #ifdef SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS - {"UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS", ERR_LIB_SSL, SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS}, - #else - {"UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS", ERR_LIB_SSL, 239}, - #endif - #ifdef SSL_R_UNABLE_TO_FIND_SSL_METHOD - {"UNABLE_TO_FIND_SSL_METHOD", ERR_LIB_SSL, SSL_R_UNABLE_TO_FIND_SSL_METHOD}, - #else - {"UNABLE_TO_FIND_SSL_METHOD", ERR_LIB_SSL, 240}, - #endif - #ifdef SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES - {"UNABLE_TO_LOAD_SSL2_MD5_ROUTINES", ERR_LIB_SSL, SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES}, - #else - {"UNABLE_TO_LOAD_SSL2_MD5_ROUTINES", ERR_LIB_SSL, 241}, - #endif - #ifdef SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES - {"UNABLE_TO_LOAD_SSL3_MD5_ROUTINES", ERR_LIB_SSL, SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES}, - #else - {"UNABLE_TO_LOAD_SSL3_MD5_ROUTINES", ERR_LIB_SSL, 242}, - #endif - #ifdef SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES - {"UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES", ERR_LIB_SSL, SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES}, - #else - {"UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES", ERR_LIB_SSL, 243}, - #endif - #ifdef SSL_R_UNEXPECTED_MESSAGE - {"UNEXPECTED_MESSAGE", ERR_LIB_SSL, SSL_R_UNEXPECTED_MESSAGE}, - #else - {"UNEXPECTED_MESSAGE", ERR_LIB_SSL, 244}, - #endif - #ifdef SSL_R_UNEXPECTED_RECORD - {"UNEXPECTED_RECORD", ERR_LIB_SSL, SSL_R_UNEXPECTED_RECORD}, - #else - {"UNEXPECTED_RECORD", ERR_LIB_SSL, 245}, - #endif - #ifdef SSL_R_UNINITIALIZED - {"UNINITIALIZED", ERR_LIB_SSL, SSL_R_UNINITIALIZED}, - #else - {"UNINITIALIZED", ERR_LIB_SSL, 276}, - #endif - #ifdef SSL_R_UNKNOWN_ALERT_TYPE - {"UNKNOWN_ALERT_TYPE", ERR_LIB_SSL, SSL_R_UNKNOWN_ALERT_TYPE}, - #else - {"UNKNOWN_ALERT_TYPE", ERR_LIB_SSL, 246}, - #endif - #ifdef SSL_R_UNKNOWN_CERTIFICATE_TYPE - {"UNKNOWN_CERTIFICATE_TYPE", ERR_LIB_SSL, SSL_R_UNKNOWN_CERTIFICATE_TYPE}, - #else - {"UNKNOWN_CERTIFICATE_TYPE", ERR_LIB_SSL, 247}, - #endif - #ifdef SSL_R_UNKNOWN_CIPHER_RETURNED - {"UNKNOWN_CIPHER_RETURNED", ERR_LIB_SSL, SSL_R_UNKNOWN_CIPHER_RETURNED}, - #else - {"UNKNOWN_CIPHER_RETURNED", ERR_LIB_SSL, 248}, - #endif - #ifdef SSL_R_UNKNOWN_CIPHER_TYPE - {"UNKNOWN_CIPHER_TYPE", ERR_LIB_SSL, SSL_R_UNKNOWN_CIPHER_TYPE}, - #else - {"UNKNOWN_CIPHER_TYPE", ERR_LIB_SSL, 249}, - #endif - #ifdef SSL_R_UNKNOWN_CMD_NAME - {"UNKNOWN_CMD_NAME", ERR_LIB_SSL, SSL_R_UNKNOWN_CMD_NAME}, - #else - {"UNKNOWN_CMD_NAME", ERR_LIB_SSL, 386}, - #endif - #ifdef SSL_R_UNKNOWN_DIGEST - {"UNKNOWN_DIGEST", ERR_LIB_SSL, SSL_R_UNKNOWN_DIGEST}, - #else - {"UNKNOWN_DIGEST", ERR_LIB_SSL, 368}, - #endif - #ifdef SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE - {"UNKNOWN_KEY_EXCHANGE_TYPE", ERR_LIB_SSL, SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE}, - #else - {"UNKNOWN_KEY_EXCHANGE_TYPE", ERR_LIB_SSL, 250}, - #endif - #ifdef SSL_R_UNKNOWN_PKEY_TYPE - {"UNKNOWN_PKEY_TYPE", ERR_LIB_SSL, SSL_R_UNKNOWN_PKEY_TYPE}, - #else - {"UNKNOWN_PKEY_TYPE", ERR_LIB_SSL, 251}, - #endif - #ifdef SSL_R_UNKNOWN_PROTOCOL - {"UNKNOWN_PROTOCOL", ERR_LIB_SSL, SSL_R_UNKNOWN_PROTOCOL}, - #else - {"UNKNOWN_PROTOCOL", ERR_LIB_SSL, 252}, - #endif - #ifdef SSL_R_UNKNOWN_REMOTE_ERROR_TYPE - {"UNKNOWN_REMOTE_ERROR_TYPE", ERR_LIB_SSL, SSL_R_UNKNOWN_REMOTE_ERROR_TYPE}, - #else - {"UNKNOWN_REMOTE_ERROR_TYPE", ERR_LIB_SSL, 253}, - #endif - #ifdef SSL_R_UNKNOWN_SSL_VERSION - {"UNKNOWN_SSL_VERSION", ERR_LIB_SSL, SSL_R_UNKNOWN_SSL_VERSION}, - #else - {"UNKNOWN_SSL_VERSION", ERR_LIB_SSL, 254}, - #endif - #ifdef SSL_R_UNKNOWN_STATE - {"UNKNOWN_STATE", ERR_LIB_SSL, SSL_R_UNKNOWN_STATE}, - #else - {"UNKNOWN_STATE", ERR_LIB_SSL, 255}, - #endif - #ifdef SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED - {"UNSAFE_LEGACY_RENEGOTIATION_DISABLED", ERR_LIB_SSL, SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED}, - #else - {"UNSAFE_LEGACY_RENEGOTIATION_DISABLED", ERR_LIB_SSL, 338}, - #endif - #ifdef SSL_R_UNSUPPORTED_CIPHER - {"UNSUPPORTED_CIPHER", ERR_LIB_SSL, SSL_R_UNSUPPORTED_CIPHER}, - #else - {"UNSUPPORTED_CIPHER", ERR_LIB_SSL, 256}, - #endif - #ifdef SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM - {"UNSUPPORTED_COMPRESSION_ALGORITHM", ERR_LIB_SSL, SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM}, - #else - {"UNSUPPORTED_COMPRESSION_ALGORITHM", ERR_LIB_SSL, 257}, - #endif - #ifdef SSL_R_UNSUPPORTED_DIGEST_TYPE - {"UNSUPPORTED_DIGEST_TYPE", ERR_LIB_SSL, SSL_R_UNSUPPORTED_DIGEST_TYPE}, - #else - {"UNSUPPORTED_DIGEST_TYPE", ERR_LIB_SSL, 326}, - #endif - #ifdef SSL_R_UNSUPPORTED_ELLIPTIC_CURVE - {"UNSUPPORTED_ELLIPTIC_CURVE", ERR_LIB_SSL, SSL_R_UNSUPPORTED_ELLIPTIC_CURVE}, - #else - {"UNSUPPORTED_ELLIPTIC_CURVE", ERR_LIB_SSL, 315}, - #endif - #ifdef SSL_R_UNSUPPORTED_PROTOCOL - {"UNSUPPORTED_PROTOCOL", ERR_LIB_SSL, SSL_R_UNSUPPORTED_PROTOCOL}, - #else - {"UNSUPPORTED_PROTOCOL", ERR_LIB_SSL, 258}, - #endif - #ifdef SSL_R_UNSUPPORTED_SSL_VERSION - {"UNSUPPORTED_SSL_VERSION", ERR_LIB_SSL, SSL_R_UNSUPPORTED_SSL_VERSION}, - #else - {"UNSUPPORTED_SSL_VERSION", ERR_LIB_SSL, 259}, - #endif - #ifdef SSL_R_UNSUPPORTED_STATUS_TYPE - {"UNSUPPORTED_STATUS_TYPE", ERR_LIB_SSL, SSL_R_UNSUPPORTED_STATUS_TYPE}, - #else - {"UNSUPPORTED_STATUS_TYPE", ERR_LIB_SSL, 329}, - #endif - #ifdef SSL_R_USE_SRTP_NOT_NEGOTIATED - {"USE_SRTP_NOT_NEGOTIATED", ERR_LIB_SSL, SSL_R_USE_SRTP_NOT_NEGOTIATED}, - #else - {"USE_SRTP_NOT_NEGOTIATED", ERR_LIB_SSL, 369}, - #endif - #ifdef SSL_R_VERSION_TOO_LOW - {"VERSION_TOO_LOW", ERR_LIB_SSL, SSL_R_VERSION_TOO_LOW}, - #else - {"VERSION_TOO_LOW", ERR_LIB_SSL, 396}, - #endif - #ifdef SSL_R_WRITE_BIO_NOT_SET - {"WRITE_BIO_NOT_SET", ERR_LIB_SSL, SSL_R_WRITE_BIO_NOT_SET}, - #else - {"WRITE_BIO_NOT_SET", ERR_LIB_SSL, 260}, - #endif - #ifdef SSL_R_WRONG_CERTIFICATE_TYPE - {"WRONG_CERTIFICATE_TYPE", ERR_LIB_SSL, SSL_R_WRONG_CERTIFICATE_TYPE}, - #else - {"WRONG_CERTIFICATE_TYPE", ERR_LIB_SSL, 383}, - #endif - #ifdef SSL_R_WRONG_CIPHER_RETURNED - {"WRONG_CIPHER_RETURNED", ERR_LIB_SSL, SSL_R_WRONG_CIPHER_RETURNED}, - #else - {"WRONG_CIPHER_RETURNED", ERR_LIB_SSL, 261}, - #endif - #ifdef SSL_R_WRONG_CURVE - {"WRONG_CURVE", ERR_LIB_SSL, SSL_R_WRONG_CURVE}, - #else - {"WRONG_CURVE", ERR_LIB_SSL, 378}, - #endif - #ifdef SSL_R_WRONG_MESSAGE_TYPE - {"WRONG_MESSAGE_TYPE", ERR_LIB_SSL, SSL_R_WRONG_MESSAGE_TYPE}, - #else - {"WRONG_MESSAGE_TYPE", ERR_LIB_SSL, 262}, - #endif - #ifdef SSL_R_WRONG_NUMBER_OF_KEY_BITS - {"WRONG_NUMBER_OF_KEY_BITS", ERR_LIB_SSL, SSL_R_WRONG_NUMBER_OF_KEY_BITS}, - #else - {"WRONG_NUMBER_OF_KEY_BITS", ERR_LIB_SSL, 263}, - #endif - #ifdef SSL_R_WRONG_SIGNATURE_LENGTH - {"WRONG_SIGNATURE_LENGTH", ERR_LIB_SSL, SSL_R_WRONG_SIGNATURE_LENGTH}, - #else - {"WRONG_SIGNATURE_LENGTH", ERR_LIB_SSL, 264}, - #endif - #ifdef SSL_R_WRONG_SIGNATURE_SIZE - {"WRONG_SIGNATURE_SIZE", ERR_LIB_SSL, SSL_R_WRONG_SIGNATURE_SIZE}, - #else - {"WRONG_SIGNATURE_SIZE", ERR_LIB_SSL, 265}, - #endif - #ifdef SSL_R_WRONG_SIGNATURE_TYPE - {"WRONG_SIGNATURE_TYPE", ERR_LIB_SSL, SSL_R_WRONG_SIGNATURE_TYPE}, - #else - {"WRONG_SIGNATURE_TYPE", ERR_LIB_SSL, 370}, - #endif - #ifdef SSL_R_WRONG_SSL_VERSION - {"WRONG_SSL_VERSION", ERR_LIB_SSL, SSL_R_WRONG_SSL_VERSION}, - #else - {"WRONG_SSL_VERSION", ERR_LIB_SSL, 266}, - #endif - #ifdef SSL_R_WRONG_VERSION_NUMBER - {"WRONG_VERSION_NUMBER", ERR_LIB_SSL, SSL_R_WRONG_VERSION_NUMBER}, - #else - {"WRONG_VERSION_NUMBER", ERR_LIB_SSL, 267}, - #endif - #ifdef SSL_R_X509_LIB - {"X509_LIB", ERR_LIB_SSL, SSL_R_X509_LIB}, - #else - {"X509_LIB", ERR_LIB_SSL, 268}, - #endif - #ifdef SSL_R_X509_VERIFICATION_SETUP_PROBLEMS - {"X509_VERIFICATION_SETUP_PROBLEMS", ERR_LIB_SSL, SSL_R_X509_VERIFICATION_SETUP_PROBLEMS}, - #else - {"X509_VERIFICATION_SETUP_PROBLEMS", ERR_LIB_SSL, 269}, - #endif - #ifdef X509_R_AKID_MISMATCH - {"AKID_MISMATCH", ERR_LIB_X509, X509_R_AKID_MISMATCH}, - #else - {"AKID_MISMATCH", ERR_LIB_X509, 110}, - #endif - #ifdef X509_R_BAD_X509_FILETYPE - {"BAD_X509_FILETYPE", ERR_LIB_X509, X509_R_BAD_X509_FILETYPE}, - #else - {"BAD_X509_FILETYPE", ERR_LIB_X509, 100}, - #endif - #ifdef X509_R_BASE64_DECODE_ERROR - {"BASE64_DECODE_ERROR", ERR_LIB_X509, X509_R_BASE64_DECODE_ERROR}, - #else - {"BASE64_DECODE_ERROR", ERR_LIB_X509, 118}, - #endif - #ifdef X509_R_CANT_CHECK_DH_KEY - {"CANT_CHECK_DH_KEY", ERR_LIB_X509, X509_R_CANT_CHECK_DH_KEY}, - #else - {"CANT_CHECK_DH_KEY", ERR_LIB_X509, 114}, - #endif - #ifdef X509_R_CERT_ALREADY_IN_HASH_TABLE - {"CERT_ALREADY_IN_HASH_TABLE", ERR_LIB_X509, X509_R_CERT_ALREADY_IN_HASH_TABLE}, - #else - {"CERT_ALREADY_IN_HASH_TABLE", ERR_LIB_X509, 101}, - #endif - #ifdef X509_R_CRL_ALREADY_DELTA - {"CRL_ALREADY_DELTA", ERR_LIB_X509, X509_R_CRL_ALREADY_DELTA}, - #else - {"CRL_ALREADY_DELTA", ERR_LIB_X509, 127}, - #endif - #ifdef X509_R_CRL_VERIFY_FAILURE - {"CRL_VERIFY_FAILURE", ERR_LIB_X509, X509_R_CRL_VERIFY_FAILURE}, - #else - {"CRL_VERIFY_FAILURE", ERR_LIB_X509, 131}, - #endif - #ifdef X509_R_ERR_ASN1_LIB - {"ERR_ASN1_LIB", ERR_LIB_X509, X509_R_ERR_ASN1_LIB}, - #else - {"ERR_ASN1_LIB", ERR_LIB_X509, 102}, - #endif - #ifdef X509_R_IDP_MISMATCH - {"IDP_MISMATCH", ERR_LIB_X509, X509_R_IDP_MISMATCH}, - #else - {"IDP_MISMATCH", ERR_LIB_X509, 128}, - #endif - #ifdef X509_R_INVALID_DIRECTORY - {"INVALID_DIRECTORY", ERR_LIB_X509, X509_R_INVALID_DIRECTORY}, - #else - {"INVALID_DIRECTORY", ERR_LIB_X509, 113}, - #endif - #ifdef X509_R_INVALID_FIELD_NAME - {"INVALID_FIELD_NAME", ERR_LIB_X509, X509_R_INVALID_FIELD_NAME}, - #else - {"INVALID_FIELD_NAME", ERR_LIB_X509, 119}, - #endif - #ifdef X509_R_INVALID_TRUST - {"INVALID_TRUST", ERR_LIB_X509, X509_R_INVALID_TRUST}, - #else - {"INVALID_TRUST", ERR_LIB_X509, 123}, - #endif - #ifdef X509_R_ISSUER_MISMATCH - {"ISSUER_MISMATCH", ERR_LIB_X509, X509_R_ISSUER_MISMATCH}, - #else - {"ISSUER_MISMATCH", ERR_LIB_X509, 129}, - #endif - #ifdef X509_R_KEY_TYPE_MISMATCH - {"KEY_TYPE_MISMATCH", ERR_LIB_X509, X509_R_KEY_TYPE_MISMATCH}, - #else - {"KEY_TYPE_MISMATCH", ERR_LIB_X509, 115}, - #endif - #ifdef X509_R_KEY_VALUES_MISMATCH - {"KEY_VALUES_MISMATCH", ERR_LIB_X509, X509_R_KEY_VALUES_MISMATCH}, - #else - {"KEY_VALUES_MISMATCH", ERR_LIB_X509, 116}, - #endif - #ifdef X509_R_LOADING_CERT_DIR - {"LOADING_CERT_DIR", ERR_LIB_X509, X509_R_LOADING_CERT_DIR}, - #else - {"LOADING_CERT_DIR", ERR_LIB_X509, 103}, - #endif - #ifdef X509_R_LOADING_DEFAULTS - {"LOADING_DEFAULTS", ERR_LIB_X509, X509_R_LOADING_DEFAULTS}, - #else - {"LOADING_DEFAULTS", ERR_LIB_X509, 104}, - #endif - #ifdef X509_R_METHOD_NOT_SUPPORTED - {"METHOD_NOT_SUPPORTED", ERR_LIB_X509, X509_R_METHOD_NOT_SUPPORTED}, - #else - {"METHOD_NOT_SUPPORTED", ERR_LIB_X509, 124}, - #endif - #ifdef X509_R_NEWER_CRL_NOT_NEWER - {"NEWER_CRL_NOT_NEWER", ERR_LIB_X509, X509_R_NEWER_CRL_NOT_NEWER}, - #else - {"NEWER_CRL_NOT_NEWER", ERR_LIB_X509, 132}, - #endif - #ifdef X509_R_NO_CERT_SET_FOR_US_TO_VERIFY - {"NO_CERT_SET_FOR_US_TO_VERIFY", ERR_LIB_X509, X509_R_NO_CERT_SET_FOR_US_TO_VERIFY}, - #else - {"NO_CERT_SET_FOR_US_TO_VERIFY", ERR_LIB_X509, 105}, - #endif - #ifdef X509_R_NO_CRL_NUMBER - {"NO_CRL_NUMBER", ERR_LIB_X509, X509_R_NO_CRL_NUMBER}, - #else - {"NO_CRL_NUMBER", ERR_LIB_X509, 130}, - #endif - #ifdef X509_R_PUBLIC_KEY_DECODE_ERROR - {"PUBLIC_KEY_DECODE_ERROR", ERR_LIB_X509, X509_R_PUBLIC_KEY_DECODE_ERROR}, - #else - {"PUBLIC_KEY_DECODE_ERROR", ERR_LIB_X509, 125}, - #endif - #ifdef X509_R_PUBLIC_KEY_ENCODE_ERROR - {"PUBLIC_KEY_ENCODE_ERROR", ERR_LIB_X509, X509_R_PUBLIC_KEY_ENCODE_ERROR}, - #else - {"PUBLIC_KEY_ENCODE_ERROR", ERR_LIB_X509, 126}, - #endif - #ifdef X509_R_SHOULD_RETRY - {"SHOULD_RETRY", ERR_LIB_X509, X509_R_SHOULD_RETRY}, - #else - {"SHOULD_RETRY", ERR_LIB_X509, 106}, - #endif - #ifdef X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN - {"UNABLE_TO_FIND_PARAMETERS_IN_CHAIN", ERR_LIB_X509, X509_R_UNABLE_TO_FIND_PARAMETERS_IN_CHAIN}, - #else - {"UNABLE_TO_FIND_PARAMETERS_IN_CHAIN", ERR_LIB_X509, 107}, - #endif - #ifdef X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY - {"UNABLE_TO_GET_CERTS_PUBLIC_KEY", ERR_LIB_X509, X509_R_UNABLE_TO_GET_CERTS_PUBLIC_KEY}, - #else - {"UNABLE_TO_GET_CERTS_PUBLIC_KEY", ERR_LIB_X509, 108}, - #endif - #ifdef X509_R_UNKNOWN_KEY_TYPE - {"UNKNOWN_KEY_TYPE", ERR_LIB_X509, X509_R_UNKNOWN_KEY_TYPE}, - #else - {"UNKNOWN_KEY_TYPE", ERR_LIB_X509, 117}, - #endif - #ifdef X509_R_UNKNOWN_NID - {"UNKNOWN_NID", ERR_LIB_X509, X509_R_UNKNOWN_NID}, - #else - {"UNKNOWN_NID", ERR_LIB_X509, 109}, - #endif - #ifdef X509_R_UNKNOWN_PURPOSE_ID - {"UNKNOWN_PURPOSE_ID", ERR_LIB_X509, X509_R_UNKNOWN_PURPOSE_ID}, - #else - {"UNKNOWN_PURPOSE_ID", ERR_LIB_X509, 121}, - #endif - #ifdef X509_R_UNKNOWN_TRUST_ID - {"UNKNOWN_TRUST_ID", ERR_LIB_X509, X509_R_UNKNOWN_TRUST_ID}, - #else - {"UNKNOWN_TRUST_ID", ERR_LIB_X509, 120}, - #endif - #ifdef X509_R_UNSUPPORTED_ALGORITHM - {"UNSUPPORTED_ALGORITHM", ERR_LIB_X509, X509_R_UNSUPPORTED_ALGORITHM}, - #else - {"UNSUPPORTED_ALGORITHM", ERR_LIB_X509, 111}, - #endif - #ifdef X509_R_WRONG_LOOKUP_TYPE - {"WRONG_LOOKUP_TYPE", ERR_LIB_X509, X509_R_WRONG_LOOKUP_TYPE}, - #else - {"WRONG_LOOKUP_TYPE", ERR_LIB_X509, 112}, - #endif - #ifdef X509_R_WRONG_TYPE - {"WRONG_TYPE", ERR_LIB_X509, X509_R_WRONG_TYPE}, - #else - {"WRONG_TYPE", ERR_LIB_X509, 122}, - #endif + {"BAD_BASE64_DECODE", ERR_LIB_PEM, MBEDTLS_ERR_PEM_INVALID_DATA + MBEDTLS_ERR_BASE64_INVALID_CHARACTER}, { NULL } }; diff --git a/third_party/python/Modules/_stat.c b/third_party/python/Modules/_stat.c index cf6784878..9c9ea4cdc 100644 --- a/third_party/python/Modules/_stat.c +++ b/third_party/python/Modules/_stat.c @@ -9,6 +9,7 @@ #include "libc/calls/weirdtypes.h" #include "libc/sysv/consts/s.h" #include "third_party/python/Include/boolobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/methodobject.h" #include "third_party/python/Include/modsupport.h" @@ -626,3 +627,8 @@ PyInit__stat(void) return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__stat = { + "_stat", + PyInit__stat, +}; diff --git a/third_party/python/Modules/_struct.c b/third_party/python/Modules/_struct.c index dbc073240..d9a9e1b01 100644 --- a/third_party/python/Modules/_struct.c +++ b/third_party/python/Modules/_struct.c @@ -12,6 +12,7 @@ #include "third_party/python/Include/descrobject.h" #include "third_party/python/Include/dictobject.h" #include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/objimpl.h" @@ -2398,3 +2399,8 @@ PyInit__struct(void) return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__struct = { + "_struct", + PyInit__struct, +}; diff --git a/third_party/python/Modules/_testcapimodule.c b/third_party/python/Modules/_testcapimodule.c index 979b6ace4..2be74d116 100644 --- a/third_party/python/Modules/_testcapimodule.c +++ b/third_party/python/Modules/_testcapimodule.c @@ -230,6 +230,9 @@ PYTHON_PROVIDE("_testcapi.unicode_legacy_string"); PYTHON_PROVIDE("_testcapi.unicode_transformdecimaltoascii"); PYTHON_PROVIDE("_testcapi.with_tp_del"); +PYTHON_YOINK("encodings.ascii"); +PYTHON_YOINK("encodings.latin_1"); + /* * C Extension module to test Python interpreter C APIs. * @@ -5216,3 +5219,8 @@ PyInit__testcapi(void) PyModule_AddObject(m, "error", TestError); return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__testcapi = { + "_testcapi", + PyInit__testcapi, +}; diff --git a/third_party/python/Modules/_tracemalloc.c b/third_party/python/Modules/_tracemalloc.c index 0f66402ad..e036d3fc2 100644 --- a/third_party/python/Modules/_tracemalloc.c +++ b/third_party/python/Modules/_tracemalloc.c @@ -10,6 +10,7 @@ #include "third_party/python/Include/dictobject.h" #include "third_party/python/Include/fileutils.h" #include "third_party/python/Include/frameobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/listobject.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" @@ -1861,3 +1862,8 @@ PyObject* return traceback_to_pyobject(traceback, NULL); } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__tracemalloc = { + "_tracemalloc", + PyInit__tracemalloc, +}; diff --git a/third_party/python/Modules/_weakref.c b/third_party/python/Modules/_weakref.c index e1acdc478..b355ac53a 100644 --- a/third_party/python/Modules/_weakref.c +++ b/third_party/python/Modules/_weakref.c @@ -5,6 +5,7 @@ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/listobject.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" diff --git a/third_party/python/Modules/_winapi.c b/third_party/python/Modules/_winapi.c index 7844b8b8c..0f3018a94 100644 --- a/third_party/python/Modules/_winapi.c +++ b/third_party/python/Modules/_winapi.c @@ -4,12 +4,35 @@ │ Python 3 │ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/nt/createfile.h" +#include "libc/nt/enum/accessmask.h" +#include "libc/nt/enum/creationdisposition.h" +#include "libc/nt/enum/fileflagandattributes.h" +#include "libc/nt/enum/fsctl.h" +#include "libc/nt/enum/processcreationflags.h" +#include "libc/nt/errors.h" +#include "libc/nt/events.h" +#include "libc/nt/files.h" +#include "libc/nt/ipc.h" +#include "libc/nt/privilege.h" +#include "libc/nt/process.h" +#include "libc/nt/runtime.h" +#include "libc/nt/struct/overlapped.h" +#include "libc/nt/struct/processinformation.h" +#include "libc/nt/struct/securityattributes.h" +#include "libc/nt/struct/startupinfo.h" +#include "libc/nt/struct/tokenprivileges.h" +#include "libc/nt/synchronization.h" +#include "libc/nt/thread.h" +#include "libc/str/str.h" #include "third_party/python/Include/Python.h" #include "third_party/python/Include/structmember.h" #include "third_party/python/Include/yoink.h" #include "third_party/python/Modules/winreparse.h" /* clang-format off */ +#define kNtIoReparseTagMountPoint 0xA0000003L + PYTHON_PROVIDE("_winapi"); /* @@ -48,19 +71,12 @@ PYTHON_PROVIDE("_winapi"); /* Licensed to PSF under a Contributor Agreement. */ /* See http://www.python.org/2.4/license for licensing details. */ -#if defined(MS_WIN32) && !defined(MS_WIN64) #define HANDLE_TO_PYNUM(handle) \ - PyLong_FromUnsignedLong((unsigned long) handle) -#define PYNUM_TO_HANDLE(obj) ((HANDLE)PyLong_AsUnsignedLong(obj)) -#define F_POINTER "k" -#define T_POINTER T_ULONG -#else -#define HANDLE_TO_PYNUM(handle) \ - PyLong_FromUnsignedLongLong((unsigned long long) handle) -#define PYNUM_TO_HANDLE(obj) ((HANDLE)PyLong_AsUnsignedLongLong(obj)) + PyLong_FromUnsignedLongLong(handle) +#define PYNUM_TO_HANDLE(obj) \ + ((int64_t)(intptr_t)PyLong_AsUnsignedLongLong(obj)) #define F_POINTER "K" #define T_POINTER T_ULONGLONG -#endif #define F_HANDLE F_POINTER #define F_DWORD "k" @@ -69,24 +85,6 @@ PYTHON_PROVIDE("_winapi"); #define DWORD_MAX 4294967295U -/* Grab CancelIoEx dynamically from kernel32 */ -static int has_CancelIoEx = -1; -static BOOL (CALLBACK *Py_CancelIoEx)(HANDLE, LPOVERLAPPED); - -static int -check_CancelIoEx() -{ - if (has_CancelIoEx == -1) - { - HINSTANCE hKernel32 = GetModuleHandle("KERNEL32"); - * (FARPROC *) &Py_CancelIoEx = GetProcAddress(hKernel32, - "CancelIoEx"); - has_CancelIoEx = (Py_CancelIoEx != NULL); - } - return has_CancelIoEx; -} - - /* * A Python object wrapping an OVERLAPPED structure and other useful data * for overlapped I/O @@ -94,9 +92,9 @@ check_CancelIoEx() typedef struct { PyObject_HEAD - OVERLAPPED overlapped; + struct NtOverlapped overlapped; /* For convenience, we store the file handle too */ - HANDLE handle; + int64_t handle; /* Whether there's I/O in flight */ int pending; /* Whether I/O completed successfully */ @@ -110,13 +108,12 @@ typedef struct { static void overlapped_dealloc(OverlappedObject *self) { - DWORD bytes; + uint32_t bytes; int err = GetLastError(); if (self->pending) { - if (check_CancelIoEx() && - Py_CancelIoEx(self->handle, &self->overlapped) && - GetOverlappedResult(self->handle, &self->overlapped, &bytes, TRUE)) + if (CancelIoEx(self->handle, &self->overlapped) && + GetOverlappedResult(self->handle, &self->overlapped, &bytes, true)) { /* The operation is no longer pending -- nothing to do. */ } @@ -164,33 +161,33 @@ def create_converter(type_, format_unit): type(name, (CConverter,), {'type': type_, 'format_unit': format_unit}) # format unit differs between platforms for these -create_converter('HANDLE', '" F_HANDLE "') -create_converter('HMODULE', '" F_HANDLE "') +create_converter('int64_t', '" F_int64_t "') +create_converter('HMODULE', '" F_int64_t "') create_converter('LPSECURITY_ATTRIBUTES', '" F_POINTER "') create_converter('BOOL', 'i') # F_BOOL used previously (always 'i') -create_converter('DWORD', 'k') # F_DWORD is always "k" (which is much shorter) +create_converter('uint32_t', 'k') # F_DWORD is always "k" (which is much shorter) create_converter('LPCTSTR', 's') create_converter('LPWSTR', 'u') create_converter('UINT', 'I') # F_UINT used previously (always 'I') -class HANDLE_return_converter(CReturnConverter): - type = 'HANDLE' +class int64_t_return_converter(CReturnConverter): + type = 'int64_t' def render(self, function, data): self.declare(data) - self.err_occurred_if("_return_value == INVALID_HANDLE_VALUE", data) + self.err_occurred_if("_return_value == kNtInvalidHandleValue", data) data.return_conversion.append( 'if (_return_value == NULL) {\n Py_RETURN_NONE;\n}\n') data.return_conversion.append( 'return_value = HANDLE_TO_PYNUM(_return_value);\n') -class DWORD_return_converter(CReturnConverter): - type = 'DWORD' +class uint32_t_return_converter(CReturnConverter): + type = 'uint32_t' def render(self, function, data): self.declare(data) - self.err_occurred_if("_return_value == DWORD_MAX", data) + self.err_occurred_if("_return_value == uint32_t_MAX", data) data.return_conversion.append( 'return_value = Py_BuildValue("k", _return_value);\n') [python start generated code]*/ @@ -209,24 +206,24 @@ static PyObject * _winapi_Overlapped_GetOverlappedResult_impl(OverlappedObject *self, int wait) /*[clinic end generated code: output=bdd0c1ed6518cd03 input=194505ee8e0e3565]*/ { - BOOL res; - DWORD transferred = 0; - DWORD err; + bool32 res; + uint32_t transferred = 0; + uint32_t err; Py_BEGIN_ALLOW_THREADS res = GetOverlappedResult(self->handle, &self->overlapped, &transferred, wait != 0); Py_END_ALLOW_THREADS - err = res ? ERROR_SUCCESS : GetLastError(); + err = res ? kNtErrorSuccess : GetLastError(); switch (err) { - case ERROR_SUCCESS: - case ERROR_MORE_DATA: - case ERROR_OPERATION_ABORTED: + case kNtErrorSuccess: + case kNtErrorMoreData: + case kNtErrorOperationAborted: self->completed = 1; self->pending = 0; break; - case ERROR_IO_INCOMPLETE: + case kNtErrorIoIncomplete: break; default: self->pending = 0; @@ -269,19 +266,14 @@ static PyObject * _winapi_Overlapped_cancel_impl(OverlappedObject *self) /*[clinic end generated code: output=fcb9ab5df4ebdae5 input=cbf3da142290039f]*/ { - BOOL res = TRUE; - + bool32 res = true; if (self->pending) { Py_BEGIN_ALLOW_THREADS - if (check_CancelIoEx()) - res = Py_CancelIoEx(self->handle, &self->overlapped); - else - res = CancelIo(self->handle); + res = CancelIoEx(self->handle, &self->overlapped); Py_END_ALLOW_THREADS } - /* CancelIoEx returns ERROR_NOT_FOUND if the I/O completed in-between */ - if (!res && GetLastError() != ERROR_NOT_FOUND) + if (!res && GetLastError() != kNtErrorNotFound) return PyErr_SetExcFromWindowsErr(PyExc_IOError, 0); self->pending = 0; Py_RETURN_NONE; @@ -296,7 +288,7 @@ static PyMethodDef overlapped_methods[] = { static PyMemberDef overlapped_members[] = { {"event", T_HANDLE, - offsetof(OverlappedObject, overlapped) + offsetof(OVERLAPPED, hEvent), + offsetof(OverlappedObject, overlapped) + offsetof(struct NtOverlapped, hEvent), READONLY, "overlapped event handle"}, {NULL} }; @@ -343,7 +335,7 @@ PyTypeObject OverlappedType = { }; static OverlappedObject * -new_overlapped(HANDLE handle) +new_overlapped(int64_t handle) { OverlappedObject *self; @@ -354,10 +346,10 @@ new_overlapped(HANDLE handle) self->read_buffer = NULL; self->pending = 0; self->completed = 0; - bzero(&self->overlapped, sizeof(OVERLAPPED)); + bzero(&self->overlapped, sizeof(struct NtOverlapped)); bzero(&self->write_buffer, sizeof(Py_buffer)); /* Manual reset, initially non-signalled */ - self->overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + self->overlapped.hEvent = CreateEvent(NULL, true, false, NULL); return self; } @@ -367,17 +359,17 @@ new_overlapped(HANDLE handle) /*[clinic input] _winapi.CloseHandle - handle: HANDLE + handle: int64_t / Close handle. [clinic start generated code]*/ static PyObject * -_winapi_CloseHandle_impl(PyObject *module, HANDLE handle) +_winapi_CloseHandle_impl(PyObject *module, int64_t handle) /*[clinic end generated code: output=7ad37345f07bd782 input=7f0e4ac36e0352b8]*/ { - BOOL success; + bool32 success; Py_BEGIN_ALLOW_THREADS success = CloseHandle(handle); @@ -392,16 +384,16 @@ _winapi_CloseHandle_impl(PyObject *module, HANDLE handle) /*[clinic input] _winapi.ConnectNamedPipe - handle: HANDLE + handle: int64_t overlapped as use_overlapped: int(c_default='0') = False [clinic start generated code]*/ static PyObject * -_winapi_ConnectNamedPipe_impl(PyObject *module, HANDLE handle, +_winapi_ConnectNamedPipe_impl(PyObject *module, int64_t handle, int use_overlapped) /*[clinic end generated code: output=335a0e7086800671 input=edc83da007ebf3be]*/ { - BOOL success; + bool32 success; OverlappedObject *overlapped = NULL; if (use_overlapped) { @@ -419,9 +411,9 @@ _winapi_ConnectNamedPipe_impl(PyObject *module, HANDLE handle, int err = GetLastError(); /* Overlapped ConnectNamedPipe never returns a success code */ assert(success == 0); - if (err == ERROR_IO_PENDING) + if (err == kNtErrorIoPending) overlapped->pending = 1; - else if (err == ERROR_PIPE_CONNECTED) + else if (err == kNtErrorPipeConnected) SetEvent(overlapped->overlapped.hEvent); else { Py_DECREF(overlapped); @@ -436,27 +428,27 @@ _winapi_ConnectNamedPipe_impl(PyObject *module, HANDLE handle, } /*[clinic input] -_winapi.CreateFile -> HANDLE +_winapi.CreateFile -> int64_t file_name: LPCTSTR - desired_access: DWORD - share_mode: DWORD + desired_access: uint32_t + share_mode: uint32_t security_attributes: LPSECURITY_ATTRIBUTES - creation_disposition: DWORD - flags_and_attributes: DWORD - template_file: HANDLE + creation_disposition: uint32_t + flags_and_attributes: uint32_t + template_file: int64_t / [clinic start generated code]*/ -static HANDLE -_winapi_CreateFile_impl(PyObject *module, LPCTSTR file_name, - DWORD desired_access, DWORD share_mode, - LPSECURITY_ATTRIBUTES security_attributes, - DWORD creation_disposition, - DWORD flags_and_attributes, HANDLE template_file) +static int64_t +_winapi_CreateFile_impl(PyObject *module, const char16_t *file_name, + uint32_t desired_access, uint32_t share_mode, + struct NtSecurityAttributes *security_attributes, + uint32_t creation_disposition, + uint32_t flags_and_attributes, int64_t template_file) /*[clinic end generated code: output=417ddcebfc5a3d53 input=6423c3e40372dbd5]*/ { - HANDLE handle; + int64_t handle; Py_BEGIN_ALLOW_THREADS handle = CreateFile(file_name, desired_access, @@ -465,7 +457,7 @@ _winapi_CreateFile_impl(PyObject *module, LPCTSTR file_name, flags_and_attributes, template_file); Py_END_ALLOW_THREADS - if (handle == INVALID_HANDLE_VALUE) + if (handle == kNtInvalidHandleValue) PyErr_SetFromWindowsErr(0); return handle; @@ -480,55 +472,44 @@ _winapi.CreateJunction [clinic start generated code]*/ static PyObject * -_winapi_CreateJunction_impl(PyObject *module, LPWSTR src_path, - LPWSTR dst_path) +_winapi_CreateJunction_impl(PyObject *module, char16_t *src_path, + char16_t *dst_path) /*[clinic end generated code: output=66b7eb746e1dfa25 input=8cd1f9964b6e3d36]*/ { /* Privilege adjustment */ - HANDLE token = NULL; - TOKEN_PRIVILEGES tp; - + int64_t token = 0; + struct NtTokenPrivileges tp; /* Reparse data buffer */ - const USHORT prefix_len = 4; - USHORT print_len = 0; - USHORT rdb_size = 0; + const uint16_t prefix_len = 4; + uint16_t print_len = 0; + uint16_t rdb_size = 0; _Py_PREPARSE_DATA_BUFFER rdb = NULL; - /* Junction point creation */ - HANDLE junction = NULL; - DWORD ret = 0; - + int64_t junction = 0; + uint32_t ret = 0; if (src_path == NULL || dst_path == NULL) - return PyErr_SetFromWindowsErr(ERROR_INVALID_PARAMETER); - - if (wcsncmp(src_path, L"\\??\\", prefix_len) == 0) - return PyErr_SetFromWindowsErr(ERROR_INVALID_PARAMETER); - + return PyErr_SetFromWindowsErr(kNtErrorInvalidParameter); + if (strncmp16(src_path, u"\\??\\", prefix_len) == 0) + return PyErr_SetFromWindowsErr(kNtErrorInvalidParameter); /* Adjust privileges to allow rewriting directory entry as a junction point. */ - if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token)) + if (!OpenProcessToken(GetCurrentProcess(), kNtTokenAdjustPrivileges, &token)) goto cleanup; - - if (!LookupPrivilegeValue(NULL, SE_RESTORE_NAME, &tp.Privileges[0].Luid)) + if (!LookupPrivilegeValue(NULL, u"SeRestorePrivilege", &tp.Privileges[0].Luid)) goto cleanup; - tp.PrivilegeCount = 1; - tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; - if (!AdjustTokenPrivileges(token, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), + tp.Privileges[0].Attributes = kNtSePrivilegeEnabled; + if (!AdjustTokenPrivileges(token, false, &tp, sizeof(struct NtTokenPrivileges), NULL, NULL)) goto cleanup; - - if (GetFileAttributesW(src_path) == INVALID_FILE_ATTRIBUTES) + if (GetFileAttributes(src_path) == -1) goto cleanup; - /* Store the absolute link target path length in print_len. */ - print_len = (USHORT)GetFullPathNameW(src_path, 0, NULL, NULL); + print_len = (uint16_t)GetFullPathName(src_path, 0, NULL, NULL); if (print_len == 0) goto cleanup; - /* NUL terminator should not be part of print_len. */ --print_len; - /* REPARSE_DATA_BUFFER usage is heavily under-documented, especially for junction points. Here's what I've learned along the way: - A junction point has two components: a print name and a substitute @@ -552,85 +533,75 @@ _winapi_CreateJunction_impl(PyObject *module, LPWSTR src_path, sizeof(rdb->MountPointReparseBuffer) - sizeof(rdb->MountPointReparseBuffer.PathBuffer) + /* Two +1's for NUL terminators. */ - (prefix_len + print_len + 1 + print_len + 1) * sizeof(WCHAR); + (prefix_len + print_len + 1 + print_len + 1) * sizeof(char16_t); rdb = (_Py_PREPARSE_DATA_BUFFER)PyMem_RawMalloc(rdb_size); if (rdb == NULL) goto cleanup; - bzero(rdb, rdb_size); - rdb->ReparseTag = IO_REPARSE_TAG_MOUNT_POINT; + rdb->ReparseTag = kNtIoReparseTagMountPoint; rdb->ReparseDataLength = rdb_size - _Py_REPARSE_DATA_BUFFER_HEADER_SIZE; rdb->MountPointReparseBuffer.SubstituteNameOffset = 0; rdb->MountPointReparseBuffer.SubstituteNameLength = - (prefix_len + print_len) * sizeof(WCHAR); + (prefix_len + print_len) * sizeof(char16_t); rdb->MountPointReparseBuffer.PrintNameOffset = - rdb->MountPointReparseBuffer.SubstituteNameLength + sizeof(WCHAR); - rdb->MountPointReparseBuffer.PrintNameLength = print_len * sizeof(WCHAR); - + rdb->MountPointReparseBuffer.SubstituteNameLength + sizeof(char16_t); + rdb->MountPointReparseBuffer.PrintNameLength = print_len * sizeof(char16_t); /* Store the full native path of link target at the substitute name offset (0). */ - wcscpy(rdb->MountPointReparseBuffer.PathBuffer, L"\\??\\"); - if (GetFullPathNameW(src_path, print_len + 1, + strcpy16(rdb->MountPointReparseBuffer.PathBuffer, u"\\??\\"); + if (GetFullPathName(src_path, print_len + 1, rdb->MountPointReparseBuffer.PathBuffer + prefix_len, NULL) == 0) goto cleanup; - /* Copy everything but the native prefix to the print name offset. */ - wcscpy(rdb->MountPointReparseBuffer.PathBuffer + + strcpy16(rdb->MountPointReparseBuffer.PathBuffer + prefix_len + print_len + 1, rdb->MountPointReparseBuffer.PathBuffer + prefix_len); - /* Create a directory for the junction point. */ - if (!CreateDirectoryW(dst_path, NULL)) + if (!CreateDirectory(dst_path, NULL)) goto cleanup; - - junction = CreateFileW(dst_path, GENERIC_READ | GENERIC_WRITE, 0, NULL, - OPEN_EXISTING, - FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS, NULL); - if (junction == INVALID_HANDLE_VALUE) + junction = CreateFile(dst_path, kNtGenericRead | kNtGenericWrite, 0, NULL, + kNtOpenExisting, + kNtFileFlagOpenReparsePoint | kNtFileFlagBackupSemantics, 0); + if (junction == kNtInvalidHandleValue) goto cleanup; - /* Make the directory entry a junction point. */ - if (!DeviceIoControl(junction, FSCTL_SET_REPARSE_POINT, rdb, rdb_size, + if (!DeviceIoControl(junction, kNtFsctlSetReparsePoint, rdb, rdb_size, NULL, 0, &ret, NULL)) goto cleanup; - cleanup: ret = GetLastError(); - CloseHandle(token); CloseHandle(junction); PyMem_RawFree(rdb); - if (ret != 0) return PyErr_SetFromWindowsErr(ret); - Py_RETURN_NONE; } /*[clinic input] -_winapi.CreateNamedPipe -> HANDLE +_winapi.CreateNamedPipe -> int64_t name: LPCTSTR - open_mode: DWORD - pipe_mode: DWORD - max_instances: DWORD - out_buffer_size: DWORD - in_buffer_size: DWORD - default_timeout: DWORD + open_mode: uint32_t + pipe_mode: uint32_t + max_instances: uint32_t + out_buffer_size: uint32_t + in_buffer_size: uint32_t + default_timeout: uint32_t security_attributes: LPSECURITY_ATTRIBUTES / [clinic start generated code]*/ -static HANDLE -_winapi_CreateNamedPipe_impl(PyObject *module, LPCTSTR name, DWORD open_mode, - DWORD pipe_mode, DWORD max_instances, - DWORD out_buffer_size, DWORD in_buffer_size, - DWORD default_timeout, - LPSECURITY_ATTRIBUTES security_attributes) +static int64_t +_winapi_CreateNamedPipe_impl(PyObject *module, const char16_t *name, uint32_t open_mode, + uint32_t pipe_mode, uint32_t max_instances, + uint32_t out_buffer_size, uint32_t in_buffer_size, + uint32_t default_timeout, + struct NtSecurityAttributes *security_attributes) /*[clinic end generated code: output=80f8c07346a94fbc input=5a73530b84d8bc37]*/ { - HANDLE handle; + int64_t handle; Py_BEGIN_ALLOW_THREADS handle = CreateNamedPipe(name, open_mode, pipe_mode, @@ -639,7 +610,7 @@ _winapi_CreateNamedPipe_impl(PyObject *module, LPCTSTR name, DWORD open_mode, security_attributes); Py_END_ALLOW_THREADS - if (handle == INVALID_HANDLE_VALUE) + if (handle == kNtInvalidHandleValue) PyErr_SetFromWindowsErr(0); return handle; @@ -650,7 +621,7 @@ _winapi.CreatePipe pipe_attrs: object Ignored internally, can be None. - size: DWORD + size: uint32_t / Create an anonymous pipe. @@ -659,12 +630,12 @@ Returns a 2-tuple of handles, to the read and write ends of the pipe. [clinic start generated code]*/ static PyObject * -_winapi_CreatePipe_impl(PyObject *module, PyObject *pipe_attrs, DWORD size) +_winapi_CreatePipe_impl(PyObject *module, PyObject *pipe_attrs, uint32_t size) /*[clinic end generated code: output=1c4411d8699f0925 input=c4f2cfa56ef68d90]*/ { - HANDLE read_pipe; - HANDLE write_pipe; - BOOL result; + int64_t read_pipe; + int64_t write_pipe; + bool32 result; Py_BEGIN_ALLOW_THREADS result = CreatePipe(&read_pipe, &write_pipe, NULL, size); @@ -695,19 +666,18 @@ getulong(PyObject* obj, const char* name) return ret; } -static HANDLE +static int64_t gethandle(PyObject* obj, const char* name) { PyObject* value; - HANDLE ret; - + int64_t ret; value = PyObject_GetAttrString(obj, name); if (! value) { PyErr_Clear(); /* FIXME: propagate error? */ - return NULL; + return 0; } if (value == Py_None) - ret = NULL; + ret = 0; else ret = PYNUM_TO_HANDLE(value); Py_DECREF(value); @@ -828,8 +798,8 @@ _winapi.CreateProcess Ignored internally, can be None. thread_attrs: object Ignored internally, can be None. - inherit_handles: BOOL - creation_flags: DWORD + inherit_handles: bool32 + creation_flags: uint32_t env_mapping: object current_directory: Py_UNICODE(accept={str, NoneType}) startup_info: object @@ -844,24 +814,24 @@ process ID, and thread ID. static PyObject * _winapi_CreateProcess_impl(PyObject *module, Py_UNICODE *application_name, Py_UNICODE *command_line, PyObject *proc_attrs, - PyObject *thread_attrs, BOOL inherit_handles, - DWORD creation_flags, PyObject *env_mapping, + PyObject *thread_attrs, bool32 inherit_handles, + uint32_t creation_flags, PyObject *env_mapping, Py_UNICODE *current_directory, PyObject *startup_info) /*[clinic end generated code: output=4652a33aff4b0ae1 input=4a43b05038d639bb]*/ { - BOOL result; - PROCESS_INFORMATION pi; - STARTUPINFOW si; + bool32 result; + struct NtProcessInformation pi; + struct NtStartupInfo si; PyObject* environment; wchar_t *wenvironment; - ZeroMemory(&si, sizeof(si)); + bzero(&si, sizeof(si)); si.cb = sizeof(si); /* note: we only support a small subset of all SI attributes */ si.dwFlags = getulong(startup_info, "dwFlags"); - si.wShowWindow = (WORD)getulong(startup_info, "wShowWindow"); + si.wShowWindow = (int16_t)getulong(startup_info, "wShowWindow"); si.hStdInput = gethandle(startup_info, "hStdInput"); si.hStdOutput = gethandle(startup_info, "hStdOutput"); si.hStdError = gethandle(startup_info, "hStdError"); @@ -886,12 +856,12 @@ _winapi_CreateProcess_impl(PyObject *module, Py_UNICODE *application_name, } Py_BEGIN_ALLOW_THREADS - result = CreateProcessW(application_name, + result = CreateProcess(application_name, command_line, NULL, NULL, inherit_handles, - creation_flags | CREATE_UNICODE_ENVIRONMENT, + creation_flags | kNtCreateUnicodeEnvironment, wenvironment, current_directory, &si, @@ -911,14 +881,14 @@ _winapi_CreateProcess_impl(PyObject *module, Py_UNICODE *application_name, } /*[clinic input] -_winapi.DuplicateHandle -> HANDLE +_winapi.DuplicateHandle -> int64_t - source_process_handle: HANDLE - source_handle: HANDLE - target_process_handle: HANDLE - desired_access: DWORD - inherit_handle: BOOL - options: DWORD = 0 + source_process_handle: int64_t + source_handle: int64_t + target_process_handle: int64_t + desired_access: uint32_t + inherit_handle: bool32 + options: uint32_t = 0 / Return a duplicate handle object. @@ -928,16 +898,16 @@ handle. Therefore, any changes to the object are reflected through both handles. [clinic start generated code]*/ -static HANDLE -_winapi_DuplicateHandle_impl(PyObject *module, HANDLE source_process_handle, - HANDLE source_handle, - HANDLE target_process_handle, - DWORD desired_access, BOOL inherit_handle, - DWORD options) +static int64_t +_winapi_DuplicateHandle_impl(PyObject *module, int64_t source_process_handle, + int64_t source_handle, + int64_t target_process_handle, + uint32_t desired_access, bool32 inherit_handle, + uint32_t options) /*[clinic end generated code: output=ad9711397b5dcd4e input=b933e3f2356a8c12]*/ { - HANDLE target_handle; - BOOL result; + int64_t target_handle; + bool32 result; Py_BEGIN_ALLOW_THREADS result = DuplicateHandle( @@ -953,7 +923,7 @@ _winapi_DuplicateHandle_impl(PyObject *module, HANDLE source_process_handle, if (! result) { PyErr_SetFromWindowsErr(GetLastError()); - return INVALID_HANDLE_VALUE; + return kNtInvalidHandleValue; } return target_handle; @@ -983,12 +953,12 @@ _winapi_ExitProcess_impl(PyObject *module, UINT ExitCode) } /*[clinic input] -_winapi.GetCurrentProcess -> HANDLE +_winapi.GetCurrentProcess -> int64_t Return a handle object for the current process. [clinic start generated code]*/ -static HANDLE +static int64_t _winapi_GetCurrentProcess_impl(PyObject *module) /*[clinic end generated code: output=ddeb4dd2ffadf344 input=b213403fd4b96b41]*/ { @@ -996,36 +966,36 @@ _winapi_GetCurrentProcess_impl(PyObject *module) } /*[clinic input] -_winapi.GetExitCodeProcess -> DWORD +_winapi.GetExitCodeProcess -> uint32_t - process: HANDLE + process: int64_t / Return the termination status of the specified process. [clinic start generated code]*/ -static DWORD -_winapi_GetExitCodeProcess_impl(PyObject *module, HANDLE process) +static uint32_t +_winapi_GetExitCodeProcess_impl(PyObject *module, int64_t process) /*[clinic end generated code: output=b4620bdf2bccf36b input=61b6bfc7dc2ee374]*/ { - DWORD exit_code; - BOOL result; + uint32_t exit_code; + bool32 result; result = GetExitCodeProcess(process, &exit_code); if (! result) { PyErr_SetFromWindowsErr(GetLastError()); - exit_code = DWORD_MAX; + exit_code = uint32_t_MAX; } return exit_code; } /*[clinic input] -_winapi.GetLastError -> DWORD +_winapi.GetLastError -> uint32_t [clinic start generated code]*/ -static DWORD +static uint32_t _winapi_GetLastError_impl(PyObject *module) /*[clinic end generated code: output=8585b827cb1a92c5 input=62d47fb9bce038ba]*/ { @@ -1052,8 +1022,8 @@ static PyObject * _winapi_GetModuleFileName_impl(PyObject *module, HMODULE module_handle) /*[clinic end generated code: output=85b4b728c5160306 input=6d66ff7deca5d11f]*/ { - BOOL result; - WCHAR filename[MAX_PATH]; + bool32 result; + char16_t filename[MAX_PATH]; result = GetModuleFileNameW(module_handle, filename, MAX_PATH); filename[MAX_PATH-1] = '\0'; @@ -1065,10 +1035,10 @@ _winapi_GetModuleFileName_impl(PyObject *module, HMODULE module_handle) } /*[clinic input] -_winapi.GetStdHandle -> HANDLE +_winapi.GetStdHandle -> int64_t - std_handle: DWORD - One of STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, or STD_ERROR_HANDLE. + std_handle: uint32_t + One of STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, or STD_ERROR_int64_t. / Return a handle to the specified standard device. @@ -1076,17 +1046,17 @@ Return a handle to the specified standard device. The integer associated with the handle object is returned. [clinic start generated code]*/ -static HANDLE -_winapi_GetStdHandle_impl(PyObject *module, DWORD std_handle) +static int64_t +_winapi_GetStdHandle_impl(PyObject *module, uint32_t std_handle) /*[clinic end generated code: output=0e613001e73ab614 input=07016b06a2fc8826]*/ { - HANDLE handle; + int64_t handle; Py_BEGIN_ALLOW_THREADS handle = GetStdHandle(std_handle); Py_END_ALLOW_THREADS - if (handle == INVALID_HANDLE_VALUE) + if (handle == kNtInvalidHandleValue) PyErr_SetFromWindowsErr(GetLastError()); return handle; @@ -1114,25 +1084,25 @@ _winapi_GetVersion_impl(PyObject *module) #pragma warning(pop) /*[clinic input] -_winapi.OpenProcess -> HANDLE +_winapi.OpenProcess -> int64_t - desired_access: DWORD - inherit_handle: BOOL - process_id: DWORD + desired_access: uint32_t + inherit_handle: bool32 + process_id: uint32_t / [clinic start generated code]*/ -static HANDLE -_winapi_OpenProcess_impl(PyObject *module, DWORD desired_access, - BOOL inherit_handle, DWORD process_id) +static int64_t +_winapi_OpenProcess_impl(PyObject *module, uint32_t desired_access, + bool32 inherit_handle, uint32_t process_id) /*[clinic end generated code: output=b42b6b81ea5a0fc3 input=ec98c4cf4ea2ec36]*/ { - HANDLE handle; + int64_t handle; handle = OpenProcess(desired_access, inherit_handle, process_id); if (handle == NULL) { PyErr_SetFromWindowsErr(0); - handle = INVALID_HANDLE_VALUE; + handle = kNtInvalidHandleValue; } return handle; @@ -1141,18 +1111,18 @@ _winapi_OpenProcess_impl(PyObject *module, DWORD desired_access, /*[clinic input] _winapi.PeekNamedPipe - handle: HANDLE + handle: int64_t size: int = 0 / [clinic start generated code]*/ static PyObject * -_winapi_PeekNamedPipe_impl(PyObject *module, HANDLE handle, int size) +_winapi_PeekNamedPipe_impl(PyObject *module, int64_t handle, int size) /*[clinic end generated code: output=d0c3e29e49d323dd input=c7aa53bfbce69d70]*/ { PyObject *buf = NULL; - DWORD nread, navail, nleft; - BOOL ret; + uint32_t nread, navail, nleft; + bool32 ret; if (size < 0) { PyErr_SetString(PyExc_ValueError, "negative size"); @@ -1189,20 +1159,20 @@ _winapi_PeekNamedPipe_impl(PyObject *module, HANDLE handle, int size) /*[clinic input] _winapi.ReadFile - handle: HANDLE - size: DWORD + handle: int64_t + size: uint32_t overlapped as use_overlapped: int(c_default='0') = False [clinic start generated code]*/ static PyObject * -_winapi_ReadFile_impl(PyObject *module, HANDLE handle, DWORD size, +_winapi_ReadFile_impl(PyObject *module, int64_t handle, uint32_t size, int use_overlapped) /*[clinic end generated code: output=d3d5b44a8201b944 input=1b7d0ed0de1e50bc]*/ { - DWORD nread; + uint32_t nread; PyObject *buf; - BOOL ret; - DWORD err; + bool32 ret; + uint32_t err; OverlappedObject *overlapped = NULL; buf = PyBytes_FromStringAndSize(NULL, size); @@ -1249,7 +1219,7 @@ _winapi_ReadFile_impl(PyObject *module, HANDLE handle, DWORD size, /*[clinic input] _winapi.SetNamedPipeHandleState - named_pipe: HANDLE + named_pipe: int64_t mode: object max_collection_count: object collect_data_timeout: object @@ -1257,14 +1227,14 @@ _winapi.SetNamedPipeHandleState [clinic start generated code]*/ static PyObject * -_winapi_SetNamedPipeHandleState_impl(PyObject *module, HANDLE named_pipe, +_winapi_SetNamedPipeHandleState_impl(PyObject *module, int64_t named_pipe, PyObject *mode, PyObject *max_collection_count, PyObject *collect_data_timeout) /*[clinic end generated code: output=f2129d222cbfa095 input=9142d72163d0faa6]*/ { PyObject *oArgs[3] = {mode, max_collection_count, collect_data_timeout}; - DWORD dwArgs[3], *pArgs[3] = {NULL, NULL, NULL}; + uint32_t dwArgs[3], *pArgs[3] = {NULL, NULL, NULL}; int i; PyErr_Clear(); @@ -1288,7 +1258,7 @@ _winapi_SetNamedPipeHandleState_impl(PyObject *module, HANDLE named_pipe, /*[clinic input] _winapi.TerminateProcess - handle: HANDLE + handle: int64_t exit_code: UINT / @@ -1296,11 +1266,11 @@ Terminate the specified process and all of its threads. [clinic start generated code]*/ static PyObject * -_winapi_TerminateProcess_impl(PyObject *module, HANDLE handle, +_winapi_TerminateProcess_impl(PyObject *module, int64_t handle, UINT exit_code) /*[clinic end generated code: output=f4e99ac3f0b1f34a input=d6bc0aa1ee3bb4df]*/ { - BOOL result; + bool32 result; result = TerminateProcess(handle, exit_code); @@ -1314,15 +1284,15 @@ _winapi_TerminateProcess_impl(PyObject *module, HANDLE handle, _winapi.WaitNamedPipe name: LPCTSTR - timeout: DWORD + timeout: uint32_t / [clinic start generated code]*/ static PyObject * -_winapi_WaitNamedPipe_impl(PyObject *module, LPCTSTR name, DWORD timeout) +_winapi_WaitNamedPipe_impl(PyObject *module, const char16_t *name, uint32_t timeout) /*[clinic end generated code: output=c2866f4439b1fe38 input=36fc781291b1862c]*/ { - BOOL success; + bool32 success; Py_BEGIN_ALLOW_THREADS success = WaitNamedPipe(name, timeout); @@ -1338,19 +1308,19 @@ _winapi_WaitNamedPipe_impl(PyObject *module, LPCTSTR name, DWORD timeout) _winapi.WaitForMultipleObjects handle_seq: object - wait_flag: BOOL - milliseconds: DWORD(c_default='INFINITE') = _winapi.INFINITE + wait_flag: bool32 + milliseconds: uint32_t(c_default='INFINITE') = _winapi.INFINITE / [clinic start generated code]*/ static PyObject * _winapi_WaitForMultipleObjects_impl(PyObject *module, PyObject *handle_seq, - BOOL wait_flag, DWORD milliseconds) + bool32 wait_flag, uint32_t milliseconds) /*[clinic end generated code: output=295e3f00b8e45899 input=36f76ca057cd28a0]*/ { - DWORD result; - HANDLE handles[MAXIMUM_WAIT_OBJECTS]; - HANDLE sigint_event = NULL; + uint32_t result; + int64_t handles[MAXIMUM_WAIT_OBJECTS]; + int64_t sigint_event = 0; Py_ssize_t nhandles, i; if (!PySequence_Check(handle_seq)) { @@ -1369,11 +1339,11 @@ _winapi_WaitForMultipleObjects_impl(PyObject *module, PyObject *handle_seq, return NULL; } for (i = 0; i < nhandles; i++) { - HANDLE h; + int64_t h; PyObject *v = PySequence_GetItem(handle_seq, i); if (v == NULL) return NULL; - if (!PyArg_Parse(v, F_HANDLE, &h)) { + if (!PyArg_Parse(v, F_int64_t, &h)) { Py_DECREF(v); return NULL; } @@ -1391,7 +1361,7 @@ _winapi_WaitForMultipleObjects_impl(PyObject *module, PyObject *handle_seq, Py_BEGIN_ALLOW_THREADS if (sigint_event != NULL) ResetEvent(sigint_event); - result = WaitForMultipleObjects((DWORD) nhandles, handles, + result = WaitForMultipleObjects((uint32_t) nhandles, handles, wait_flag, milliseconds); Py_END_ALLOW_THREADS @@ -1408,8 +1378,8 @@ _winapi_WaitForMultipleObjects_impl(PyObject *module, PyObject *handle_seq, /*[clinic input] _winapi.WaitForSingleObject -> long - handle: HANDLE - milliseconds: DWORD + handle: int64_t + milliseconds: uint32_t / Wait for a single object. @@ -1420,11 +1390,11 @@ in milliseconds. [clinic start generated code]*/ static long -_winapi_WaitForSingleObject_impl(PyObject *module, HANDLE handle, - DWORD milliseconds) +_winapi_WaitForSingleObject_impl(PyObject *module, int64_t handle, + uint32_t milliseconds) /*[clinic end generated code: output=3c4715d8f1b39859 input=443d1ab076edc7b1]*/ { - DWORD result; + uint32_t result; Py_BEGIN_ALLOW_THREADS result = WaitForSingleObject(handle, milliseconds); @@ -1441,20 +1411,20 @@ _winapi_WaitForSingleObject_impl(PyObject *module, HANDLE handle, /*[clinic input] _winapi.WriteFile - handle: HANDLE + handle: int64_t buffer: object overlapped as use_overlapped: int(c_default='0') = False [clinic start generated code]*/ static PyObject * -_winapi_WriteFile_impl(PyObject *module, HANDLE handle, PyObject *buffer, +_winapi_WriteFile_impl(PyObject *module, int64_t handle, PyObject *buffer, int use_overlapped) /*[clinic end generated code: output=2ca80f6bf3fa92e3 input=51846a5af52053fd]*/ { Py_buffer _buf, *buf; - DWORD len, written; - BOOL ret; - DWORD err; + uint32_t len, written; + bool32 ret; + uint32_t err; OverlappedObject *overlapped = NULL; if (use_overlapped) { @@ -1472,7 +1442,7 @@ _winapi_WriteFile_impl(PyObject *module, HANDLE handle, PyObject *buffer, } Py_BEGIN_ALLOW_THREADS - len = (DWORD)Py_MIN(buf->len, DWORD_MAX); + len = (uint32_t)Py_MIN(buf->len, uint32_t_MAX); ret = WriteFile(handle, buf->buf, len, &written, overlapped ? &overlapped->overlapped : NULL); Py_END_ALLOW_THREADS diff --git a/third_party/python/Modules/arraymodule.c b/third_party/python/Modules/arraymodule.c index 694f4861f..926f0b2eb 100644 --- a/third_party/python/Modules/arraymodule.c +++ b/third_party/python/Modules/arraymodule.c @@ -3057,3 +3057,8 @@ PyInit_array(void) { return PyModuleDef_Init(&arraymodule); } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_array = { + "array", + PyInit_array, +}; diff --git a/third_party/python/Modules/atexitmodule.c b/third_party/python/Modules/atexitmodule.c index 184ff5e57..b390f44bb 100644 --- a/third_party/python/Modules/atexitmodule.c +++ b/third_party/python/Modules/atexitmodule.c @@ -5,6 +5,7 @@ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/moduleobject.h" @@ -371,3 +372,8 @@ PyInit_atexit(void) _Py_PyAtExit(atexit_callfuncs); return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_atexit = { + "atexit", + PyInit_atexit, +}; diff --git a/third_party/python/Modules/audioop.c b/third_party/python/Modules/audioop.c index 5c0a8a0cb..55e0322c7 100644 --- a/third_party/python/Modules/audioop.c +++ b/third_party/python/Modules/audioop.c @@ -8,6 +8,7 @@ #include "libc/math.h" #include "third_party/python/Include/dictobject.h" #include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/object.h" @@ -1963,3 +1964,8 @@ PyInit_audioop(void) PyDict_SetItemString(d,"error",AudioopError); return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_audioop = { + "audioop", + PyInit_audioop, +}; diff --git a/third_party/python/Modules/binascii.c b/third_party/python/Modules/binascii.c index 164505713..c0fd6f28f 100644 --- a/third_party/python/Modules/binascii.c +++ b/third_party/python/Modules/binascii.c @@ -8,6 +8,7 @@ #include "libc/assert.h" #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/pyctype.h" @@ -1474,3 +1475,8 @@ PyInit_binascii(void) } return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_binascii = { + "binascii", + PyInit_binascii, +}; diff --git a/third_party/python/Modules/cjkcodecs/_codecs_cn.c b/third_party/python/Modules/cjkcodecs/_codecs_cn.c index f87efb420..9dc82517d 100644 --- a/third_party/python/Modules/cjkcodecs/_codecs_cn.c +++ b/third_party/python/Modules/cjkcodecs/_codecs_cn.c @@ -4,6 +4,7 @@ │ Python 3 │ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/python/Include/import.h" #include "third_party/python/Include/yoink.h" #include "third_party/python/Modules/cjkcodecs/cjkcodecs.h" #include "third_party/python/Modules/cjkcodecs/mappings_cn.inc" @@ -477,3 +478,8 @@ BEGIN_CODECS_LIST END_CODECS_LIST I_AM_A_MODULE_FOR(cn) + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__codecs_cn = { + "_codecs_cn", + PyInit__codecs_cn, +}; diff --git a/third_party/python/Modules/cjkcodecs/_codecs_hk.c b/third_party/python/Modules/cjkcodecs/_codecs_hk.c index c86a51759..ecf3ef458 100644 --- a/third_party/python/Modules/cjkcodecs/_codecs_hk.c +++ b/third_party/python/Modules/cjkcodecs/_codecs_hk.c @@ -5,6 +5,7 @@ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ #define USING_IMPORTED_MAPS +#include "third_party/python/Include/import.h" #include "third_party/python/Include/yoink.h" #include "third_party/python/Modules/cjkcodecs/cjkcodecs.h" #include "third_party/python/Modules/cjkcodecs/mappings_hk.inc" @@ -202,3 +203,8 @@ BEGIN_CODECS_LIST END_CODECS_LIST I_AM_A_MODULE_FOR(hk) + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__codecs_hk = { + "_codecs_hk", + PyInit__codecs_hk, +}; diff --git a/third_party/python/Modules/cjkcodecs/_codecs_iso2022.c b/third_party/python/Modules/cjkcodecs/_codecs_iso2022.c index 934d80272..f366c5005 100644 --- a/third_party/python/Modules/cjkcodecs/_codecs_iso2022.c +++ b/third_party/python/Modules/cjkcodecs/_codecs_iso2022.c @@ -22,6 +22,7 @@ #include "third_party/python/Modules/cjkcodecs/emu_jisx0213_2000.inc" #include "third_party/python/Modules/cjkcodecs/cjkcodecs.h" #include "third_party/python/Include/yoink.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Modules/cjkcodecs/mappings_jisx0213_pair.inc" PYTHON_PROVIDE("_codecs_iso2022"); @@ -1153,3 +1154,8 @@ BEGIN_CODECS_LIST END_CODECS_LIST I_AM_A_MODULE_FOR(iso2022) + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__codecs_iso2022 = { + "_codecs_iso2022", + PyInit__codecs_iso2022, +}; diff --git a/third_party/python/Modules/cjkcodecs/_codecs_jp.c b/third_party/python/Modules/cjkcodecs/_codecs_jp.c index 084592ce0..fd6421a62 100644 --- a/third_party/python/Modules/cjkcodecs/_codecs_jp.c +++ b/third_party/python/Modules/cjkcodecs/_codecs_jp.c @@ -19,6 +19,7 @@ #include "third_party/python/Modules/cjkcodecs/mappings_jisx0213_pair.inc" #include "third_party/python/Modules/cjkcodecs/alg_jisx0201.inc" #include "third_party/python/Include/yoink.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Modules/cjkcodecs/emu_jisx0213_2000.inc" PYTHON_PROVIDE("_codecs_jp"); @@ -780,3 +781,8 @@ BEGIN_CODECS_LIST END_CODECS_LIST I_AM_A_MODULE_FOR(jp) + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__codecs_jp = { + "_codecs_jp", + PyInit__codecs_jp, +}; diff --git a/third_party/python/Modules/cjkcodecs/_codecs_kr.c b/third_party/python/Modules/cjkcodecs/_codecs_kr.c index fffc47976..a5c3a5955 100644 --- a/third_party/python/Modules/cjkcodecs/_codecs_kr.c +++ b/third_party/python/Modules/cjkcodecs/_codecs_kr.c @@ -14,6 +14,7 @@ #include "third_party/python/Modules/cjkcodecs/cjkcodecs.h" #include "third_party/python/Include/yoink.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Modules/cjkcodecs/mappings_kr.inc" PYTHON_PROVIDE("_codecs_kr"); @@ -481,3 +482,8 @@ BEGIN_CODECS_LIST END_CODECS_LIST I_AM_A_MODULE_FOR(kr) + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__codecs_kr = { + "_codecs_kr", + PyInit__codecs_kr, +}; diff --git a/third_party/python/Modules/cjkcodecs/_codecs_tw.c b/third_party/python/Modules/cjkcodecs/_codecs_tw.c index 48b0ebdf5..8507153a6 100644 --- a/third_party/python/Modules/cjkcodecs/_codecs_tw.c +++ b/third_party/python/Modules/cjkcodecs/_codecs_tw.c @@ -7,6 +7,7 @@ #include "third_party/python/Modules/cjkcodecs/cjkcodecs.h" #include "third_party/python/Include/yoink.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Modules/cjkcodecs/mappings_tw.inc" PYTHON_PROVIDE("_codecs_tw"); @@ -148,3 +149,8 @@ BEGIN_CODECS_LIST END_CODECS_LIST I_AM_A_MODULE_FOR(tw) + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__codecs_tw = { + "_codecs_tw", + PyInit__codecs_tw, +}; diff --git a/third_party/python/Modules/cjkcodecs/multibytecodec.c b/third_party/python/Modules/cjkcodecs/multibytecodec.c index 967071fab..16334c444 100644 --- a/third_party/python/Modules/cjkcodecs/multibytecodec.c +++ b/third_party/python/Modules/cjkcodecs/multibytecodec.c @@ -8,6 +8,7 @@ #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/codecs.h" #include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/objimpl.h" @@ -1952,3 +1953,8 @@ PyInit__multibytecodec(void) } return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__multibytecodec = { + "_multibytecodec", + PyInit__multibytecodec, +}; diff --git a/third_party/python/Modules/clinic/_hashopenssl.inc b/third_party/python/Modules/clinic/_hashmbedtls.inc similarity index 100% rename from third_party/python/Modules/clinic/_hashopenssl.inc rename to third_party/python/Modules/clinic/_hashmbedtls.inc diff --git a/third_party/python/Modules/clinic/_winapi.inc b/third_party/python/Modules/clinic/_winapi.inc index 7c50a9685..c35bb4dde 100644 --- a/third_party/python/Modules/clinic/_winapi.inc +++ b/third_party/python/Modules/clinic/_winapi.inc @@ -73,13 +73,13 @@ PyDoc_STRVAR(_winapi_CloseHandle__doc__, {"CloseHandle", (PyCFunction)_winapi_CloseHandle, METH_O, _winapi_CloseHandle__doc__}, static PyObject * -_winapi_CloseHandle_impl(PyObject *module, HANDLE handle); +_winapi_CloseHandle_impl(PyObject *module, int64_t handle); static PyObject * _winapi_CloseHandle(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - HANDLE handle; + int64_t handle; if (!PyArg_Parse(arg, "" F_HANDLE ":CloseHandle", &handle)) { goto exit; @@ -99,7 +99,7 @@ PyDoc_STRVAR(_winapi_ConnectNamedPipe__doc__, {"ConnectNamedPipe", (PyCFunction)_winapi_ConnectNamedPipe, METH_FASTCALL, _winapi_ConnectNamedPipe__doc__}, static PyObject * -_winapi_ConnectNamedPipe_impl(PyObject *module, HANDLE handle, +_winapi_ConnectNamedPipe_impl(PyObject *module, int64_t handle, int use_overlapped); static PyObject * @@ -108,7 +108,7 @@ _winapi_ConnectNamedPipe(PyObject *module, PyObject **args, Py_ssize_t nargs, Py PyObject *return_value = NULL; static const char * const _keywords[] = {"handle", "overlapped", NULL}; static _PyArg_Parser _parser = {"" F_HANDLE "|i:ConnectNamedPipe", _keywords, 0}; - HANDLE handle; + int64_t handle; int use_overlapped = 0; if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, @@ -131,35 +131,35 @@ PyDoc_STRVAR(_winapi_CreateFile__doc__, #define _WINAPI_CREATEFILE_METHODDEF \ {"CreateFile", (PyCFunction)_winapi_CreateFile, METH_VARARGS, _winapi_CreateFile__doc__}, -static HANDLE -_winapi_CreateFile_impl(PyObject *module, LPCTSTR file_name, - DWORD desired_access, DWORD share_mode, - LPSECURITY_ATTRIBUTES security_attributes, - DWORD creation_disposition, - DWORD flags_and_attributes, HANDLE template_file); +static int64_t +_winapi_CreateFile_impl(PyObject *module, const char16_t *file_name, + uint32_t desired_access, uint32_t share_mode, + struct NtSecurityAttributes *security_attributes, + uint32_t creation_disposition, + uint32_t flags_and_attributes, int64_t template_file); static PyObject * _winapi_CreateFile(PyObject *module, PyObject *args) { PyObject *return_value = NULL; - LPCTSTR file_name; - DWORD desired_access; - DWORD share_mode; - LPSECURITY_ATTRIBUTES security_attributes; - DWORD creation_disposition; - DWORD flags_and_attributes; - HANDLE template_file; - HANDLE _return_value; + const char16_t *file_name; + uint32_t desired_access; + uint32_t share_mode; + struct NtSecurityAttributes *security_attributes; + uint32_t creation_disposition; + uint32_t flags_and_attributes; + int64_t template_file; + int64_t _return_value; if (!PyArg_ParseTuple(args, "skk" F_POINTER "kk" F_HANDLE ":CreateFile", &file_name, &desired_access, &share_mode, &security_attributes, &creation_disposition, &flags_and_attributes, &template_file)) { goto exit; } _return_value = _winapi_CreateFile_impl(module, file_name, desired_access, share_mode, security_attributes, creation_disposition, flags_and_attributes, template_file); - if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { + if ((_return_value == kNtInvalidHandleValue) && PyErr_Occurred()) { goto exit; } - if (_return_value == NULL) { + if (!_return_value) { Py_RETURN_NONE; } return_value = HANDLE_TO_PYNUM(_return_value); @@ -177,15 +177,15 @@ PyDoc_STRVAR(_winapi_CreateJunction__doc__, {"CreateJunction", (PyCFunction)_winapi_CreateJunction, METH_VARARGS, _winapi_CreateJunction__doc__}, static PyObject * -_winapi_CreateJunction_impl(PyObject *module, LPWSTR src_path, - LPWSTR dst_path); +_winapi_CreateJunction_impl(PyObject *module, char16_t *src_path, + char16_t *dst_path); static PyObject * _winapi_CreateJunction(PyObject *module, PyObject *args) { PyObject *return_value = NULL; - LPWSTR src_path; - LPWSTR dst_path; + char16_t *src_path; + char16_t *dst_path; if (!PyArg_ParseTuple(args, "uu:CreateJunction", &src_path, &dst_path)) { @@ -207,36 +207,36 @@ PyDoc_STRVAR(_winapi_CreateNamedPipe__doc__, #define _WINAPI_CREATENAMEDPIPE_METHODDEF \ {"CreateNamedPipe", (PyCFunction)_winapi_CreateNamedPipe, METH_VARARGS, _winapi_CreateNamedPipe__doc__}, -static HANDLE -_winapi_CreateNamedPipe_impl(PyObject *module, LPCTSTR name, DWORD open_mode, - DWORD pipe_mode, DWORD max_instances, - DWORD out_buffer_size, DWORD in_buffer_size, - DWORD default_timeout, - LPSECURITY_ATTRIBUTES security_attributes); +static int64_t +_winapi_CreateNamedPipe_impl(PyObject *module, const char16_t *name, uint32_t open_mode, + uint32_t pipe_mode, uint32_t max_instances, + uint32_t out_buffer_size, uint32_t in_buffer_size, + uint32_t default_timeout, + struct NtSecurityAttributes *security_attributes); static PyObject * _winapi_CreateNamedPipe(PyObject *module, PyObject *args) { PyObject *return_value = NULL; - LPCTSTR name; - DWORD open_mode; - DWORD pipe_mode; - DWORD max_instances; - DWORD out_buffer_size; - DWORD in_buffer_size; - DWORD default_timeout; - LPSECURITY_ATTRIBUTES security_attributes; - HANDLE _return_value; + const char16_t *name; + uint32_t open_mode; + uint32_t pipe_mode; + uint32_t max_instances; + uint32_t out_buffer_size; + uint32_t in_buffer_size; + uint32_t default_timeout; + struct NtSecurityAttributes *security_attributes; + int64_t _return_value; if (!PyArg_ParseTuple(args, "skkkkkk" F_POINTER ":CreateNamedPipe", &name, &open_mode, &pipe_mode, &max_instances, &out_buffer_size, &in_buffer_size, &default_timeout, &security_attributes)) { goto exit; } _return_value = _winapi_CreateNamedPipe_impl(module, name, open_mode, pipe_mode, max_instances, out_buffer_size, in_buffer_size, default_timeout, security_attributes); - if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { + if ((_return_value == kNtInvalidHandleValue) && PyErr_Occurred()) { goto exit; } - if (_return_value == NULL) { + if (!_return_value) { Py_RETURN_NONE; } return_value = HANDLE_TO_PYNUM(_return_value); @@ -260,14 +260,14 @@ PyDoc_STRVAR(_winapi_CreatePipe__doc__, {"CreatePipe", (PyCFunction)_winapi_CreatePipe, METH_VARARGS, _winapi_CreatePipe__doc__}, static PyObject * -_winapi_CreatePipe_impl(PyObject *module, PyObject *pipe_attrs, DWORD size); +_winapi_CreatePipe_impl(PyObject *module, PyObject *pipe_attrs, uint32_t size); static PyObject * _winapi_CreatePipe(PyObject *module, PyObject *args) { PyObject *return_value = NULL; PyObject *pipe_attrs; - DWORD size; + uint32_t size; if (!PyArg_ParseTuple(args, "Ok:CreatePipe", &pipe_attrs, &size)) { @@ -301,8 +301,8 @@ PyDoc_STRVAR(_winapi_CreateProcess__doc__, static PyObject * _winapi_CreateProcess_impl(PyObject *module, Py_UNICODE *application_name, Py_UNICODE *command_line, PyObject *proc_attrs, - PyObject *thread_attrs, BOOL inherit_handles, - DWORD creation_flags, PyObject *env_mapping, + PyObject *thread_attrs, bool32 inherit_handles, + uint32_t creation_flags, PyObject *env_mapping, Py_UNICODE *current_directory, PyObject *startup_info); @@ -314,8 +314,8 @@ _winapi_CreateProcess(PyObject *module, PyObject *args) Py_UNICODE *command_line; PyObject *proc_attrs; PyObject *thread_attrs; - BOOL inherit_handles; - DWORD creation_flags; + bool32 inherit_handles; + uint32_t creation_flags; PyObject *env_mapping; Py_UNICODE *current_directory; PyObject *startup_info; @@ -345,34 +345,34 @@ PyDoc_STRVAR(_winapi_DuplicateHandle__doc__, #define _WINAPI_DUPLICATEHANDLE_METHODDEF \ {"DuplicateHandle", (PyCFunction)_winapi_DuplicateHandle, METH_VARARGS, _winapi_DuplicateHandle__doc__}, -static HANDLE -_winapi_DuplicateHandle_impl(PyObject *module, HANDLE source_process_handle, - HANDLE source_handle, - HANDLE target_process_handle, - DWORD desired_access, BOOL inherit_handle, - DWORD options); +static int64_t +_winapi_DuplicateHandle_impl(PyObject *module, int64_t source_process_handle, + int64_t source_handle, + int64_t target_process_handle, + uint32_t desired_access, bool32 inherit_handle, + uint32_t options); static PyObject * _winapi_DuplicateHandle(PyObject *module, PyObject *args) { PyObject *return_value = NULL; - HANDLE source_process_handle; - HANDLE source_handle; - HANDLE target_process_handle; - DWORD desired_access; - BOOL inherit_handle; - DWORD options = 0; - HANDLE _return_value; + int64_t source_process_handle; + int64_t source_handle; + int64_t target_process_handle; + uint32_t desired_access; + bool32 inherit_handle; + uint32_t options = 0; + int64_t _return_value; if (!PyArg_ParseTuple(args, "" F_HANDLE "" F_HANDLE "" F_HANDLE "ki|k:DuplicateHandle", &source_process_handle, &source_handle, &target_process_handle, &desired_access, &inherit_handle, &options)) { goto exit; } _return_value = _winapi_DuplicateHandle_impl(module, source_process_handle, source_handle, target_process_handle, desired_access, inherit_handle, options); - if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { + if ((_return_value == kNtInvalidHandleValue) && PyErr_Occurred()) { goto exit; } - if (_return_value == NULL) { + if (!_return_value) { Py_RETURN_NONE; } return_value = HANDLE_TO_PYNUM(_return_value); @@ -390,13 +390,13 @@ PyDoc_STRVAR(_winapi_ExitProcess__doc__, {"ExitProcess", (PyCFunction)_winapi_ExitProcess, METH_O, _winapi_ExitProcess__doc__}, static PyObject * -_winapi_ExitProcess_impl(PyObject *module, UINT ExitCode); +_winapi_ExitProcess_impl(PyObject *module, unsigned ExitCode); static PyObject * _winapi_ExitProcess(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - UINT ExitCode; + unsigned ExitCode; if (!PyArg_Parse(arg, "I:ExitProcess", &ExitCode)) { goto exit; @@ -416,20 +416,20 @@ PyDoc_STRVAR(_winapi_GetCurrentProcess__doc__, #define _WINAPI_GETCURRENTPROCESS_METHODDEF \ {"GetCurrentProcess", (PyCFunction)_winapi_GetCurrentProcess, METH_NOARGS, _winapi_GetCurrentProcess__doc__}, -static HANDLE +static int64_t _winapi_GetCurrentProcess_impl(PyObject *module); static PyObject * _winapi_GetCurrentProcess(PyObject *module, PyObject *Py_UNUSED(ignored)) { PyObject *return_value = NULL; - HANDLE _return_value; + int64_t _return_value; _return_value = _winapi_GetCurrentProcess_impl(module); - if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { + if ((_return_value == kNtInvalidHandleValue) && PyErr_Occurred()) { goto exit; } - if (_return_value == NULL) { + if (!_return_value) { Py_RETURN_NONE; } return_value = HANDLE_TO_PYNUM(_return_value); @@ -447,21 +447,21 @@ PyDoc_STRVAR(_winapi_GetExitCodeProcess__doc__, #define _WINAPI_GETEXITCODEPROCESS_METHODDEF \ {"GetExitCodeProcess", (PyCFunction)_winapi_GetExitCodeProcess, METH_O, _winapi_GetExitCodeProcess__doc__}, -static DWORD -_winapi_GetExitCodeProcess_impl(PyObject *module, HANDLE process); +static uint32_t +_winapi_GetExitCodeProcess_impl(PyObject *module, int64_t process); static PyObject * _winapi_GetExitCodeProcess(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - HANDLE process; - DWORD _return_value; + int64_t process; + uint32_t _return_value; if (!PyArg_Parse(arg, "" F_HANDLE ":GetExitCodeProcess", &process)) { goto exit; } _return_value = _winapi_GetExitCodeProcess_impl(module, process); - if ((_return_value == DWORD_MAX) && PyErr_Occurred()) { + if ((_return_value == UINT_MAX) && PyErr_Occurred()) { goto exit; } return_value = Py_BuildValue("k", _return_value); @@ -478,17 +478,17 @@ PyDoc_STRVAR(_winapi_GetLastError__doc__, #define _WINAPI_GETLASTERROR_METHODDEF \ {"GetLastError", (PyCFunction)_winapi_GetLastError, METH_NOARGS, _winapi_GetLastError__doc__}, -static DWORD +static uint32_t _winapi_GetLastError_impl(PyObject *module); static PyObject * _winapi_GetLastError(PyObject *module, PyObject *Py_UNUSED(ignored)) { PyObject *return_value = NULL; - DWORD _return_value; + uint32_t _return_value; _return_value = _winapi_GetLastError_impl(module); - if ((_return_value == DWORD_MAX) && PyErr_Occurred()) { + if ((_return_value == UINT_MAX) && PyErr_Occurred()) { goto exit; } return_value = Py_BuildValue("k", _return_value); @@ -514,19 +514,17 @@ PyDoc_STRVAR(_winapi_GetModuleFileName__doc__, {"GetModuleFileName", (PyCFunction)_winapi_GetModuleFileName, METH_O, _winapi_GetModuleFileName__doc__}, static PyObject * -_winapi_GetModuleFileName_impl(PyObject *module, HMODULE module_handle); +_winapi_GetModuleFileName_impl(PyObject *module, int64_t module_handle); static PyObject * _winapi_GetModuleFileName(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - HMODULE module_handle; - + int64_t module_handle; if (!PyArg_Parse(arg, "" F_HANDLE ":GetModuleFileName", &module_handle)) { goto exit; } return_value = _winapi_GetModuleFileName_impl(module, module_handle); - exit: return return_value; } @@ -538,31 +536,31 @@ PyDoc_STRVAR(_winapi_GetStdHandle__doc__, "Return a handle to the specified standard device.\n" "\n" " std_handle\n" -" One of STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, or STD_ERROR_HANDLE.\n" +" One of STD_INPUT_int64_t, STD_OUTPUT_int64_t, or STD_ERROR_int64_t.\n" "\n" "The integer associated with the handle object is returned."); #define _WINAPI_GETSTDHANDLE_METHODDEF \ {"GetStdHandle", (PyCFunction)_winapi_GetStdHandle, METH_O, _winapi_GetStdHandle__doc__}, -static HANDLE -_winapi_GetStdHandle_impl(PyObject *module, DWORD std_handle); +static int64_t +_winapi_GetStdHandle_impl(PyObject *module, uint32_t std_handle); static PyObject * _winapi_GetStdHandle(PyObject *module, PyObject *arg) { PyObject *return_value = NULL; - DWORD std_handle; - HANDLE _return_value; + uint32_t std_handle; + int64_t _return_value; if (!PyArg_Parse(arg, "k:GetStdHandle", &std_handle)) { goto exit; } _return_value = _winapi_GetStdHandle_impl(module, std_handle); - if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { + if ((_return_value == kNtInvalidHandleValue) && PyErr_Occurred()) { goto exit; } - if (_return_value == NULL) { + if (!_return_value) { Py_RETURN_NONE; } return_value = HANDLE_TO_PYNUM(_return_value); @@ -607,28 +605,28 @@ PyDoc_STRVAR(_winapi_OpenProcess__doc__, #define _WINAPI_OPENPROCESS_METHODDEF \ {"OpenProcess", (PyCFunction)_winapi_OpenProcess, METH_VARARGS, _winapi_OpenProcess__doc__}, -static HANDLE -_winapi_OpenProcess_impl(PyObject *module, DWORD desired_access, - BOOL inherit_handle, DWORD process_id); +static int64_t +_winapi_OpenProcess_impl(PyObject *module, uint32_t desired_access, + bool32 inherit_handle, uint32_t process_id); static PyObject * _winapi_OpenProcess(PyObject *module, PyObject *args) { PyObject *return_value = NULL; - DWORD desired_access; - BOOL inherit_handle; - DWORD process_id; - HANDLE _return_value; + uint32_t desired_access; + bool32 inherit_handle; + uint32_t process_id; + int64_t _return_value; if (!PyArg_ParseTuple(args, "kik:OpenProcess", &desired_access, &inherit_handle, &process_id)) { goto exit; } _return_value = _winapi_OpenProcess_impl(module, desired_access, inherit_handle, process_id); - if ((_return_value == INVALID_HANDLE_VALUE) && PyErr_Occurred()) { + if ((_return_value == kNtInvalidHandleValue) && PyErr_Occurred()) { goto exit; } - if (_return_value == NULL) { + if (!_return_value) { Py_RETURN_NONE; } return_value = HANDLE_TO_PYNUM(_return_value); @@ -646,13 +644,13 @@ PyDoc_STRVAR(_winapi_PeekNamedPipe__doc__, {"PeekNamedPipe", (PyCFunction)_winapi_PeekNamedPipe, METH_VARARGS, _winapi_PeekNamedPipe__doc__}, static PyObject * -_winapi_PeekNamedPipe_impl(PyObject *module, HANDLE handle, int size); +_winapi_PeekNamedPipe_impl(PyObject *module, int64_t handle, int size); static PyObject * _winapi_PeekNamedPipe(PyObject *module, PyObject *args) { PyObject *return_value = NULL; - HANDLE handle; + int64_t handle; int size = 0; if (!PyArg_ParseTuple(args, "" F_HANDLE "|i:PeekNamedPipe", @@ -674,7 +672,7 @@ PyDoc_STRVAR(_winapi_ReadFile__doc__, {"ReadFile", (PyCFunction)_winapi_ReadFile, METH_FASTCALL, _winapi_ReadFile__doc__}, static PyObject * -_winapi_ReadFile_impl(PyObject *module, HANDLE handle, DWORD size, +_winapi_ReadFile_impl(PyObject *module, int64_t handle, uint32_t size, int use_overlapped); static PyObject * @@ -683,8 +681,8 @@ _winapi_ReadFile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject * PyObject *return_value = NULL; static const char * const _keywords[] = {"handle", "size", "overlapped", NULL}; static _PyArg_Parser _parser = {"" F_HANDLE "k|i:ReadFile", _keywords, 0}; - HANDLE handle; - DWORD size; + int64_t handle; + uint32_t size; int use_overlapped = 0; if (!_PyArg_ParseStack(args, nargs, kwnames, &_parser, @@ -707,7 +705,7 @@ PyDoc_STRVAR(_winapi_SetNamedPipeHandleState__doc__, {"SetNamedPipeHandleState", (PyCFunction)_winapi_SetNamedPipeHandleState, METH_VARARGS, _winapi_SetNamedPipeHandleState__doc__}, static PyObject * -_winapi_SetNamedPipeHandleState_impl(PyObject *module, HANDLE named_pipe, +_winapi_SetNamedPipeHandleState_impl(PyObject *module, int64_t named_pipe, PyObject *mode, PyObject *max_collection_count, PyObject *collect_data_timeout); @@ -716,7 +714,7 @@ static PyObject * _winapi_SetNamedPipeHandleState(PyObject *module, PyObject *args) { PyObject *return_value = NULL; - HANDLE named_pipe; + int64_t named_pipe; PyObject *mode; PyObject *max_collection_count; PyObject *collect_data_timeout; @@ -741,15 +739,15 @@ PyDoc_STRVAR(_winapi_TerminateProcess__doc__, {"TerminateProcess", (PyCFunction)_winapi_TerminateProcess, METH_VARARGS, _winapi_TerminateProcess__doc__}, static PyObject * -_winapi_TerminateProcess_impl(PyObject *module, HANDLE handle, - UINT exit_code); +_winapi_TerminateProcess_impl(PyObject *module, int64_t handle, + unsigned exit_code); static PyObject * _winapi_TerminateProcess(PyObject *module, PyObject *args) { PyObject *return_value = NULL; - HANDLE handle; - UINT exit_code; + int64_t handle; + unsigned exit_code; if (!PyArg_ParseTuple(args, "" F_HANDLE "I:TerminateProcess", &handle, &exit_code)) { @@ -770,14 +768,14 @@ PyDoc_STRVAR(_winapi_WaitNamedPipe__doc__, {"WaitNamedPipe", (PyCFunction)_winapi_WaitNamedPipe, METH_VARARGS, _winapi_WaitNamedPipe__doc__}, static PyObject * -_winapi_WaitNamedPipe_impl(PyObject *module, LPCTSTR name, DWORD timeout); +_winapi_WaitNamedPipe_impl(PyObject *module, const char *name, uint32_t timeout); static PyObject * _winapi_WaitNamedPipe(PyObject *module, PyObject *args) { PyObject *return_value = NULL; - LPCTSTR name; - DWORD timeout; + const char *name; + uint32_t timeout; if (!PyArg_ParseTuple(args, "sk:WaitNamedPipe", &name, &timeout)) { @@ -800,15 +798,15 @@ PyDoc_STRVAR(_winapi_WaitForMultipleObjects__doc__, static PyObject * _winapi_WaitForMultipleObjects_impl(PyObject *module, PyObject *handle_seq, - BOOL wait_flag, DWORD milliseconds); + bool32 wait_flag, uint32_t milliseconds); static PyObject * _winapi_WaitForMultipleObjects(PyObject *module, PyObject *args) { PyObject *return_value = NULL; PyObject *handle_seq; - BOOL wait_flag; - DWORD milliseconds = INFINITE; + bool32 wait_flag; + uint32_t milliseconds = -1; if (!PyArg_ParseTuple(args, "Oi|k:WaitForMultipleObjects", &handle_seq, &wait_flag, &milliseconds)) { @@ -834,15 +832,15 @@ PyDoc_STRVAR(_winapi_WaitForSingleObject__doc__, {"WaitForSingleObject", (PyCFunction)_winapi_WaitForSingleObject, METH_VARARGS, _winapi_WaitForSingleObject__doc__}, static long -_winapi_WaitForSingleObject_impl(PyObject *module, HANDLE handle, - DWORD milliseconds); +_winapi_WaitForSingleObject_impl(PyObject *module, int64_t handle, + uint32_t milliseconds); static PyObject * _winapi_WaitForSingleObject(PyObject *module, PyObject *args) { PyObject *return_value = NULL; - HANDLE handle; - DWORD milliseconds; + int64_t handle; + uint32_t milliseconds; long _return_value; if (!PyArg_ParseTuple(args, "" F_HANDLE "k:WaitForSingleObject", @@ -868,7 +866,7 @@ PyDoc_STRVAR(_winapi_WriteFile__doc__, {"WriteFile", (PyCFunction)_winapi_WriteFile, METH_FASTCALL, _winapi_WriteFile__doc__}, static PyObject * -_winapi_WriteFile_impl(PyObject *module, HANDLE handle, PyObject *buffer, +_winapi_WriteFile_impl(PyObject *module, int64_t handle, PyObject *buffer, int use_overlapped); static PyObject * @@ -877,7 +875,7 @@ _winapi_WriteFile(PyObject *module, PyObject **args, Py_ssize_t nargs, PyObject PyObject *return_value = NULL; static const char * const _keywords[] = {"handle", "buffer", "overlapped", NULL}; static _PyArg_Parser _parser = {"" F_HANDLE "O|i:WriteFile", _keywords, 0}; - HANDLE handle; + int64_t handle; PyObject *buffer; int use_overlapped = 0; diff --git a/third_party/python/Modules/cmathmodule.c b/third_party/python/Modules/cmathmodule.c index 1adce7a75..308307890 100644 --- a/third_party/python/Modules/cmathmodule.c +++ b/third_party/python/Modules/cmathmodule.c @@ -11,6 +11,7 @@ #include "third_party/python/Include/complexobject.h" #include "third_party/python/Include/dtoa.h" #include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/object.h" #include "third_party/python/Include/pyerrors.h" @@ -1456,3 +1457,8 @@ PyInit_cmath(void) }) return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_cmath = { + "cmath", + PyInit_cmath, +}; diff --git a/third_party/python/Modules/config.c b/third_party/python/Modules/config.c index e0eaf101b..41de4dcb7 100644 --- a/third_party/python/Modules/config.c +++ b/third_party/python/Modules/config.c @@ -4,216 +4,111 @@ │ Python 3 │ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/python/Include/Python.h" +#include "third_party/python/Include/cosmo.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/pyport.h" /* clang-format off */ -/* Generated automatically from ./Modules/config.c.in by makesetup. */ -/* -*- C -*- *********************************************** -Copyright (c) 2000, BeOpen.com. -Copyright (c) 1995-2000, Corporation for National Research Initiatives. -Copyright (c) 1990-1995, Stichting Mathematisch Centrum. -All rights reserved. - -See the file "Misc/COPYRIGHT" for information on usage and -redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. -******************************************************************/ - -/* Module configuration */ - -/* !!! !!! !!! This file is edited by the makesetup script !!! !!! !!! */ - -/* This file contains the table of built-in modules. - See create_builtin() in import.c. */ - -#include "third_party/python/Include/pyport.h" -#include "third_party/python/Include/pyport.h" -#include "third_party/python/Include/Python.h" -#include "third_party/python/Include/import.h" -#include "third_party/python/Include/cosmo.h" - -PyObject* PyInit__decimal(void); -PyObject* PyInit_audioop(void); -PyObject* PyInit_posix(void); -PyObject* PyInit_errno(void); -PyObject* PyInit_pwd(void); -PyObject* PyInit__sre(void); -PyObject* PyInit__codecs(void); -PyObject* PyInit__functools(void); -PyObject* PyInit__operator(void); -PyObject* PyInit__collections(void); -PyObject* PyInit_itertools(void); -PyObject* PyInit_atexit(void); -PyObject* PyInit__signal(void); -PyObject* PyInit__stat(void); -PyObject* PyInit_time(void); -PyObject* PyInit__locale(void); -PyObject* PyInit__io(void); -PyObject* PyInit_zipimport(void); -PyObject* PyInit_faulthandler(void); -PyObject* PyInit__hashlib(void); -#ifdef MODE_DBG -PyObject* PyInit__tracemalloc(void); -#endif -PyObject* PyInit__symtable(void); -PyObject* PyInit_array(void); -PyObject* PyInit_cmath(void); -PyObject* PyInit_math(void); -PyObject* PyInit__struct(void); -PyObject* PyInit__weakref(void); -PyObject* PyInit__testcapi(void); -PyObject* PyInit__random(void); -PyObject* PyInit__elementtree(void); -PyObject* PyInit__pickle(void); -PyObject* PyInit__datetime(void); -PyObject* PyInit__bisect(void); -PyObject* PyInit__heapq(void); -PyObject* PyInit_unicodedata(void); -PyObject* PyInit_fcntl(void); -PyObject* PyInit__bz2(void); -PyObject* PyInit_grp(void); -PyObject* PyInit_select(void); -PyObject* PyInit_mmap(void); -PyObject* PyInit__csv(void); -PyObject* PyInit__socket(void); -PyObject* PyInit_resource(void); -PyObject* PyInit__posixsubprocess(void); -PyObject* PyInit__multiprocessing(void); -PyObject* PyInit__md5(void); -PyObject* PyInit__sha1(void); -PyObject* PyInit__sha256(void); -PyObject* PyInit__sha512(void); -PyObject* PyInit__sha3(void); -PyObject* PyInit_syslog(void); -PyObject* PyInit_binascii(void); -PyObject* PyInit_parser(void); -PyObject* PyInit_fpectl(void); -PyObject* PyInit_zlib(void); -PyObject* PyInit_pyexpat(void); -PyObject* PyInit__multibytecodec(void); -PyObject* PyInit__codecs_cn(void); -PyObject* PyInit__codecs_hk(void); -PyObject* PyInit__codecs_iso2022(void); -PyObject* PyInit__codecs_jp(void); -PyObject* PyInit__codecs_kr(void); -PyObject* PyInit__codecs_tw(void); -PyObject* PyInit__json(void); -PyObject* PyInit__lsprof(void); -PyObject* PyInit__opcode(void); -PyObject* PyInit_termios(void); +PyObject *PyInit__ast(void); +PyObject *PyInit__bisect(void); +PyObject *PyInit__bz2(void); +PyObject *PyInit__codecs(void); +PyObject *PyInit__codecs_cn(void); +PyObject *PyInit__codecs_hk(void); +PyObject *PyInit__codecs_iso2022(void); +PyObject *PyInit__codecs_jp(void); +PyObject *PyInit__codecs_kr(void); +PyObject *PyInit__codecs_tw(void); +PyObject *PyInit__collections(void); +PyObject *PyInit__csv(void); +PyObject *PyInit__datetime(void); +PyObject *PyInit__decimal(void); +PyObject *PyInit__elementtree(void); +PyObject *PyInit__functools(void); +PyObject *PyInit__hashlib(void); +PyObject *PyInit__heapq(void); +PyObject *PyInit__io(void); +PyObject *PyInit__json(void); +PyObject *PyInit__locale(void); +PyObject *PyInit__lsprof(void); +PyObject *PyInit__md5(void); +PyObject *PyInit__multibytecodec(void); +PyObject *PyInit__multiprocessing(void); +PyObject *PyInit__opcode(void); +PyObject *PyInit__operator(void); +PyObject *PyInit__pickle(void); +PyObject *PyInit__posixsubprocess(void); +PyObject *PyInit__random(void); +PyObject *PyInit__sha1(void); +PyObject *PyInit__sha256(void); +PyObject *PyInit__sha3(void); +PyObject *PyInit__sha512(void); +PyObject *PyInit__signal(void); +PyObject *PyInit__socket(void); PyObject *PyInit__sqlite3(void); +PyObject *PyInit__sre(void); +PyObject *PyInit__stat(void); +PyObject *PyInit__string(void); +PyObject *PyInit__struct(void); +PyObject *PyInit__symtable(void); +PyObject *PyInit__testcapi(void); +PyObject *PyInit__tracemalloc(void); +PyObject *PyInit__weakref(void); +PyObject *PyInit_array(void); +PyObject *PyInit_atexit(void); +PyObject *PyInit_audioop(void); +PyObject *PyInit_binascii(void); +PyObject *PyInit_cmath(void); +PyObject *PyInit_cosmo(void); +PyObject *PyInit_errno(void); +PyObject *PyInit_faulthandler(void); +PyObject *PyInit_fcntl(void); +PyObject *PyInit_fpectl(void); +PyObject *PyInit_gc(void); +PyObject *PyInit_grp(void); +PyObject *PyInit_imp(void); +PyObject *PyInit_itertools(void); +PyObject *PyInit_math(void); +PyObject *PyInit_mmap(void); +PyObject *PyInit_parser(void); +PyObject *PyInit_posix(void); +PyObject *PyInit_pwd(void); +PyObject *PyInit_pyexpat(void); +PyObject *PyInit_resource(void); +PyObject *PyInit_select(void); +PyObject *PyInit_syslog(void); +PyObject *PyInit_termios(void); +PyObject *PyInit_time(void); +PyObject *PyInit_unicodedata(void); +PyObject *PyInit_zipimport(void); +PyObject *PyInit_zlib(void); +PyObject *PyMarshal_Init(void); +PyObject *_PyWarnings_Init(void); -/* -- ADDMODULE MARKER 1 -- */ - -PyObject* PyMarshal_Init(void); -PyObject* PyInit_imp(void); -PyObject* PyInit_cosmo(void); -PyObject* PyInit_gc(void); -PyObject* PyInit__ast(void); -PyObject* _PyWarnings_Init(void); -PyObject* PyInit__string(void); - -struct _inittab _PyImport_Inittab[] = { - - {"_decimal", PyInit__decimal}, +_Alignas(16) _Section(".rodata.pytab.0") const struct _inittab _PyImport_Inittab[0]; +_Alignas(16) _Section(".rodata.pytab.2") const struct _inittab _PyImport_Inittab2[] = { {"posix", PyInit_posix}, {"errno", PyInit_errno}, - {"pwd", PyInit_pwd}, {"_sre", PyInit__sre}, {"_codecs", PyInit__codecs}, {"_functools", PyInit__functools}, {"_operator", PyInit__operator}, {"_collections", PyInit__collections}, {"itertools", PyInit_itertools}, - {"atexit", PyInit_atexit}, {"_signal", PyInit__signal}, - {"_stat", PyInit__stat}, - {"time", PyInit_time}, {"_locale", PyInit__locale}, {"_io", PyInit__io}, - {"faulthandler", PyInit_faulthandler}, -#ifdef USE_TRACEMALLOC - {"_tracemalloc", PyInit__tracemalloc}, -#endif - {"_symtable", PyInit__symtable}, - {"_hashlib", PyInit__hashlib}, - {"_bz2module", PyInit__bz2}, - {"array", PyInit_array}, - {"cmath", PyInit_cmath}, - {"math", PyInit_math}, - {"_struct", PyInit__struct}, {"_weakref", PyInit__weakref}, - {"_testcapi", PyInit__testcapi}, - {"_random", PyInit__random}, - {"_pickle", PyInit__pickle}, - {"_datetime", PyInit__datetime}, - {"_bisect", PyInit__bisect}, {"_heapq", PyInit__heapq}, - {"unicodedata", PyInit_unicodedata}, - {"fcntl", PyInit_fcntl}, - {"grp", PyInit_grp}, - {"select", PyInit_select}, - {"mmap", PyInit_mmap}, - {"_csv", PyInit__csv}, - {"_socket", PyInit__socket}, - {"resource", PyInit_resource}, - {"_posixsubprocess", PyInit__posixsubprocess}, - {"_multiprocessing", PyInit__multiprocessing}, - {"_md5", PyInit__md5}, - {"_sha1", PyInit__sha1}, - {"_sha256", PyInit__sha256}, - {"_sha512", PyInit__sha512}, - {"_sha3", PyInit__sha3}, - {"syslog", PyInit_syslog}, - {"binascii", PyInit_binascii}, - {"parser", PyInit_parser}, - {"fpectl", PyInit_fpectl}, - {"pyexpat", PyInit_pyexpat}, - {"_multibytecodec", PyInit__multibytecodec}, - {"_json", PyInit__json}, - {"_opcode", PyInit__opcode}, - {"termios", PyInit_termios}, - -#if !IsTiny() - {"zlib", PyInit_zlib}, - {"sqlite3", PyInit__sqlite3}, - {"zipimport", PyInit_zipimport}, - {"_elementtree", PyInit__elementtree}, - {"_codecs_cn", PyInit__codecs_cn}, - {"_codecs_hk", PyInit__codecs_hk}, - {"_codecs_iso2022", PyInit__codecs_iso2022}, - {"_codecs_jp", PyInit__codecs_jp}, - {"_codecs_kr", PyInit__codecs_kr}, - {"_codecs_tw", PyInit__codecs_tw}, - {"audioop", PyInit_audioop}, - {"_lsprof", PyInit__lsprof}, -#endif - -/* -- ADDMODULE MARKER 2 -- */ - - /* This module lives in marshal.c */ {"marshal", PyMarshal_Init}, - - /* This lives in import.c */ {"_imp", PyInit_imp}, - - /* This lives in cosmomodule.c */ {"_cosmo", PyInit_cosmo}, - - /* This lives in Python/Python-ast.c */ {"_ast", PyInit__ast}, - - /* These entries are here for sys.builtin_module_names */ {"builtins", NULL}, {"sys", NULL}, - - /* This lives in gcmodule.c */ {"gc", PyInit_gc}, - - /* This lives in _warnings.c */ - {"_warnings", _PyWarnings_Init}, - - /* This lives in Objects/unicodeobject.c */ + {"_warnings", _PyWarnings_Init}, {"_string", PyInit__string}, - - /* Sentinel */ {0, 0} }; diff --git a/third_party/python/Modules/errnomodule.c b/third_party/python/Modules/errnomodule.c index f6006e91e..806d24b0c 100644 --- a/third_party/python/Modules/errnomodule.c +++ b/third_party/python/Modules/errnomodule.c @@ -8,6 +8,7 @@ #include "libc/errno.h" #include "libc/nt/errors.h" #include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/methodobject.h" #include "third_party/python/Include/modsupport.h" diff --git a/third_party/python/Modules/faulthandler.c b/third_party/python/Modules/faulthandler.c index 9fd2464a6..9fd141a41 100644 --- a/third_party/python/Modules/faulthandler.c +++ b/third_party/python/Modules/faulthandler.c @@ -1436,3 +1436,8 @@ void _PyFaulthandler_Fini(void) } #endif } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_faulthandler = { + "faulthandler", + PyInit_faulthandler, +}; diff --git a/third_party/python/Modules/fcntlmodule.c b/third_party/python/Modules/fcntlmodule.c index d9c8b4e95..919d375ba 100644 --- a/third_party/python/Modules/fcntlmodule.c +++ b/third_party/python/Modules/fcntlmodule.c @@ -16,6 +16,7 @@ #include "third_party/python/Include/bytesobject.h" #include "third_party/python/Include/ceval.h" #include "third_party/python/Include/fileobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/object.h" @@ -697,3 +698,8 @@ PyInit_fcntl(void) return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_fcntl = { + "fcntl", + PyInit_fcntl, +}; diff --git a/third_party/python/Modules/fpectlmodule.c b/third_party/python/Modules/fpectlmodule.c index aa24240f7..962c893b0 100644 --- a/third_party/python/Modules/fpectlmodule.c +++ b/third_party/python/Modules/fpectlmodule.c @@ -6,6 +6,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/runtime/runtime.h" #include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/methodobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/moduleobject.h" @@ -275,3 +276,8 @@ PyMODINIT_FUNC PyInit_fpectl(void) PyDict_SetItemString(d, "error", fpe_error); return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_fpectl = { + "fpectl", + PyInit_fpectl, +}; diff --git a/third_party/python/Modules/getpath.c b/third_party/python/Modules/getpath.c index 949dfc349..d23fed498 100644 --- a/third_party/python/Modules/getpath.c +++ b/third_party/python/Modules/getpath.c @@ -8,6 +8,7 @@ #include "libc/calls/calls.h" #include "libc/calls/struct/stat.h" #include "libc/errno.h" +#include "libc/log/log.h" #include "libc/mem/alloca.h" #include "libc/mem/mem.h" #include "libc/runtime/gc.internal.h" @@ -125,12 +126,12 @@ wchar_t *Py_GetProgramName(void); #define LANDMARK L"os.py" #endif -static const wchar_t limited_search_path[] = L"/zip/.python"; +#define LIMITED_SEARCH_PATH L"/zip/.python" static wchar_t *progpath; -static wchar_t *prefix = limited_search_path; -static wchar_t *exec_prefix = limited_search_path; -static wchar_t *module_search_path = limited_search_path; +static wchar_t *prefix = LIMITED_SEARCH_PATH; +static wchar_t *exec_prefix = LIMITED_SEARCH_PATH; +static wchar_t *module_search_path = LIMITED_SEARCH_PATH; /* Get file status. Encode the path to the locale encoding. */ @@ -667,3 +668,11 @@ Py_GetProgramFullPath(void) } return progpath; } + +void +Py_LimitedPath(void) +{ + prefix = wcscpy(PyMem_RawMalloc((wcslen(LIMITED_SEARCH_PATH) + 1) * 4), LIMITED_SEARCH_PATH); + exec_prefix = wcscpy(PyMem_RawMalloc((wcslen(LIMITED_SEARCH_PATH) + 1) * 4), LIMITED_SEARCH_PATH); + module_search_path = wcscpy(PyMem_RawMalloc((wcslen(LIMITED_SEARCH_PATH) + 1) * 4), LIMITED_SEARCH_PATH); +} diff --git a/third_party/python/Modules/grpmodule.c b/third_party/python/Modules/grpmodule.c index 8f0c584b4..6a74e5326 100644 --- a/third_party/python/Modules/grpmodule.c +++ b/third_party/python/Modules/grpmodule.c @@ -8,6 +8,7 @@ #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/bytesobject.h" #include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/listobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/object.h" @@ -276,3 +277,8 @@ PyInit_grp(void) initialized = 1; return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_grp = { + "grp", + PyInit_grp, +}; diff --git a/third_party/python/Modules/hashtable.c b/third_party/python/Modules/hashtable.c index dae163c91..602f3c642 100644 --- a/third_party/python/Modules/hashtable.c +++ b/third_party/python/Modules/hashtable.c @@ -9,6 +9,11 @@ #include "third_party/python/Modules/hashtable.h" /* clang-format off */ +asm(".ident\t\"\\n\\n\ +cfuhash (bsd-3)\\n\ +Copyright (c) 2005 Don Owens\""); +asm(".include \"libc/disclaimer.inc\""); + /* The implementation of the hash table (_Py_hashtable_t) is based on the cfuhash project: http://sourceforge.net/projects/libcfu/ diff --git a/third_party/python/Modules/itertoolsmodule.c b/third_party/python/Modules/itertoolsmodule.c index b6651f62f..1be915cd3 100644 --- a/third_party/python/Modules/itertoolsmodule.c +++ b/third_party/python/Modules/itertoolsmodule.c @@ -8,6 +8,7 @@ #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/boolobject.h" #include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/objimpl.h" diff --git a/third_party/python/Modules/mathmodule.c b/third_party/python/Modules/mathmodule.c index ce138c7ef..21a1b1a38 100644 --- a/third_party/python/Modules/mathmodule.c +++ b/third_party/python/Modules/mathmodule.c @@ -11,6 +11,7 @@ #include "third_party/python/Include/boolobject.h" #include "third_party/python/Include/dtoa.h" #include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/pyerrors.h" @@ -2227,3 +2228,8 @@ PyInit_math(void) finally: return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_math = { + "math", + PyInit_math, +}; diff --git a/third_party/python/Modules/md5module.c b/third_party/python/Modules/md5module.c index 2f5076598..0c005a3ce 100644 --- a/third_party/python/Modules/md5module.c +++ b/third_party/python/Modules/md5module.c @@ -8,6 +8,7 @@ #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/bytesobject.h" #include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/objimpl.h" @@ -596,3 +597,8 @@ PyInit__md5(void) PyModule_AddObject(m, "MD5Type", (PyObject *)&MD5type); return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__md5 = { + "_md5", + PyInit__md5, +}; diff --git a/third_party/python/Modules/mmapmodule.c b/third_party/python/Modules/mmapmodule.c index f5b1251a6..028017a36 100644 --- a/third_party/python/Modules/mmapmodule.c +++ b/third_party/python/Modules/mmapmodule.c @@ -18,6 +18,7 @@ #include "third_party/python/Include/descrobject.h" #include "third_party/python/Include/dictobject.h" #include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/objimpl.h" @@ -1491,3 +1492,8 @@ PyInit_mmap(void) setint(dict, "ACCESS_COPY", ACCESS_COPY); return module; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_mmap = { + "mmap", + PyInit_mmap, +}; diff --git a/third_party/python/Modules/parsermodule.c b/third_party/python/Modules/parsermodule.c index fe61baa55..db1a3c5d8 100644 --- a/third_party/python/Modules/parsermodule.c +++ b/third_party/python/Modules/parsermodule.c @@ -1253,3 +1253,8 @@ PyInit_parser(void) } return module; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_parser = { + "parser", + PyInit_parser, +}; diff --git a/third_party/python/Modules/posixmodule.c b/third_party/python/Modules/posixmodule.c index 854bd885c..4d628dd82 100644 --- a/third_party/python/Modules/posixmodule.c +++ b/third_party/python/Modules/posixmodule.c @@ -7,6 +7,7 @@ #define PY_SSIZE_T_CLEAN #include "libc/alg/alg.h" #include "libc/assert.h" +#include "libc/bits/weaken.h" #include "libc/calls/calls.h" #include "libc/calls/internal.h" #include "libc/calls/makedev.h" @@ -16,6 +17,7 @@ #include "libc/calls/termios.h" #include "libc/calls/weirdtypes.h" #include "libc/errno.h" +#include "libc/log/log.h" #include "libc/nt/dll.h" #include "libc/nt/enum/sw.h" #include "libc/runtime/dlfcn.h" @@ -36,6 +38,7 @@ #include "libc/sysv/consts/st.h" #include "libc/sysv/consts/w.h" #include "libc/sysv/consts/waitid.h" +#include "libc/sysv/errfuns.h" #include "libc/time/time.h" #include "third_party/musl/passwd.h" #include "third_party/python/Include/abstract.h" @@ -1816,6 +1819,7 @@ posix_do_stat(const char *function_name, path_t *path, #endif /* HAVE_FSTATAT */ result = STAT(path->narrow, &st); #endif /* MS_WINDOWS */ + Py_END_ALLOW_THREADS if (result != 0) { diff --git a/third_party/python/Modules/pwdmodule.c b/third_party/python/Modules/pwdmodule.c index bd4ae48eb..4231f0ef4 100644 --- a/third_party/python/Modules/pwdmodule.c +++ b/third_party/python/Modules/pwdmodule.c @@ -6,6 +6,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "third_party/musl/passwd.h" #include "third_party/python/Include/bytesobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/listobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/object.h" @@ -264,3 +265,8 @@ PyInit_pwd(void) PyModule_AddObject(m, "struct_passwd", (PyObject *) &StructPwdType); return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_pwd = { + "pwd", + PyInit_pwd, +}; diff --git a/third_party/python/Modules/pyexpat.c b/third_party/python/Modules/pyexpat.c index 96a67ae9c..29196f6a2 100644 --- a/third_party/python/Modules/pyexpat.c +++ b/third_party/python/Modules/pyexpat.c @@ -11,6 +11,7 @@ #include "third_party/python/Include/ceval.h" #include "third_party/python/Include/dictobject.h" #include "third_party/python/Include/frameobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/objimpl.h" @@ -46,6 +47,9 @@ PYTHON_PROVIDE("pyexpat.model"); PYTHON_PROVIDE("pyexpat.native_encoding"); PYTHON_PROVIDE("pyexpat.version_info"); +PYTHON_YOINK("encodings.ascii"); +PYTHON_YOINK("encodings.utf_8"); + /* Do not emit Clinic output to a file as that wreaks havoc with conditionally included methods. */ /*[clinic input] @@ -2036,3 +2040,8 @@ static struct HandlerInfo handler_info[] = { dump buffer [clinic start generated code]*/ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=524ce2e021e4eba6]*/ + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_pyexpat = { + "pyexpat", + PyInit_pyexpat, +}; diff --git a/third_party/python/Modules/resource.c b/third_party/python/Modules/resource.c index 00ab76372..a5a23b3f3 100644 --- a/third_party/python/Modules/resource.c +++ b/third_party/python/Modules/resource.c @@ -14,6 +14,7 @@ #include "libc/sysv/consts/rusage.h" #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/pyerrors.h" @@ -416,3 +417,8 @@ PyInit_resource(void) initialized = 1; return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_resource = { + "resource", + PyInit_resource, +}; diff --git a/third_party/python/Modules/selectmodule.c b/third_party/python/Modules/selectmodule.c index cb3fda8c7..2cf403f61 100644 --- a/third_party/python/Modules/selectmodule.c +++ b/third_party/python/Modules/selectmodule.c @@ -21,6 +21,7 @@ #include "third_party/python/Include/descrobject.h" #include "third_party/python/Include/dictobject.h" #include "third_party/python/Include/fileobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/objimpl.h" @@ -2604,3 +2605,8 @@ PyInit_select(void) #endif /* HAVE_KQUEUE */ return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_select = { + "select", + PyInit_select, +}; diff --git a/third_party/python/Modules/sha1module.c b/third_party/python/Modules/sha1module.c index d1695a36b..0eab95cbb 100644 --- a/third_party/python/Modules/sha1module.c +++ b/third_party/python/Modules/sha1module.c @@ -8,6 +8,7 @@ #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/bytesobject.h" #include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/objimpl.h" @@ -579,3 +580,8 @@ PyInit__sha1(void) PyModule_AddObject(m, "SHA1Type", (PyObject *)&SHA1type); return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__sha1 = { + "_sha1", + PyInit__sha1, +}; diff --git a/third_party/python/Modules/sha256module.c b/third_party/python/Modules/sha256module.c index 10b6bb750..61c63fe40 100644 --- a/third_party/python/Modules/sha256module.c +++ b/third_party/python/Modules/sha256module.c @@ -7,6 +7,7 @@ #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/bytesobject.h" #include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/objimpl.h" @@ -744,3 +745,8 @@ PyInit__sha256(void) return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__sha256 = { + "_sha256", + PyInit__sha256, +}; diff --git a/third_party/python/Modules/sha512module.c b/third_party/python/Modules/sha512module.c index 0c42e8c38..bab279981 100644 --- a/third_party/python/Modules/sha512module.c +++ b/third_party/python/Modules/sha512module.c @@ -7,6 +7,7 @@ #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/bytesobject.h" #include "third_party/python/Include/descrobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/object.h" @@ -818,3 +819,8 @@ PyInit__sha512(void) PyModule_AddObject(m, "SHA512Type", (PyObject *)&SHA512type); return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__sha512 = { + "_sha512", + PyInit__sha512, +}; diff --git a/third_party/python/Modules/socketmodule.c b/third_party/python/Modules/socketmodule.c index b2390ebad..3b08986c5 100644 --- a/third_party/python/Modules/socketmodule.c +++ b/third_party/python/Modules/socketmodule.c @@ -40,6 +40,7 @@ #include "third_party/python/Include/descrobject.h" #include "third_party/python/Include/fileutils.h" #include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/objimpl.h" @@ -7196,3 +7197,8 @@ PyInit__socket(void) return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__socket = { + "_socket", + PyInit__socket, +}; diff --git a/third_party/python/Modules/symtablemodule.c b/third_party/python/Modules/symtablemodule.c index 936202a12..a41ee504c 100644 --- a/third_party/python/Modules/symtablemodule.c +++ b/third_party/python/Modules/symtablemodule.c @@ -6,6 +6,7 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "third_party/python/Include/Python-ast.h" #include "third_party/python/Include/code.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/pyerrors.h" #include "third_party/python/Include/pymacro.h" @@ -133,3 +134,8 @@ PyInit__symtable(void) } return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab__symtable = { + "_symtable", + PyInit__symtable, +}; diff --git a/third_party/python/Modules/syslogmodule.c b/third_party/python/Modules/syslogmodule.c index df19fa472..c1fd502fe 100644 --- a/third_party/python/Modules/syslogmodule.c +++ b/third_party/python/Modules/syslogmodule.c @@ -7,6 +7,7 @@ #include "libc/sock/syslog.h" #include "libc/sysv/consts/log.h" #include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/listobject.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" @@ -59,6 +60,12 @@ PYTHON_PROVIDE("syslog.openlog"); PYTHON_PROVIDE("syslog.setlogmask"); PYTHON_PROVIDE("syslog.syslog"); +asm(".ident\t\"\\n\\n\ +syslogmodule (mit)\\n\ +Copyright 1994 by Lance Ellinghouse\\n\ +Cathedral City, California Republic, United States of America\""); +asm(".include \"libc/disclaimer.inc\""); + /*********************************************************** Copyright 1994 by Lance Ellinghouse, Cathedral City, California Republic, United States of America. @@ -396,3 +403,8 @@ PyInit_syslog(void) return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_syslog = { + "syslog", + PyInit_syslog, +}; diff --git a/third_party/python/Modules/termios.c b/third_party/python/Modules/termios.c index 06d4ab055..63814c1b1 100644 --- a/third_party/python/Modules/termios.c +++ b/third_party/python/Modules/termios.c @@ -16,6 +16,7 @@ #include "libc/sysv/consts/termios.h" #include "third_party/python/Include/bytesobject.h" #include "third_party/python/Include/fileobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/listobject.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" @@ -790,3 +791,8 @@ PyInit_termios(void) return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_termios = { + "termios", + PyInit_termios, +}; diff --git a/third_party/python/Modules/timemodule.c b/third_party/python/Modules/timemodule.c index 34d4793ea..9fd4db3f4 100644 --- a/third_party/python/Modules/timemodule.c +++ b/third_party/python/Modules/timemodule.c @@ -68,6 +68,8 @@ PYTHON_PROVIDE("time.timezone"); PYTHON_PROVIDE("time.tzname"); PYTHON_PROVIDE("time.tzset"); +PYTHON_YOINK("_strptime"); + typedef int clockid_t; #undef HAVE_CLOCK_SETTIME @@ -1477,3 +1479,8 @@ pysleep(_PyTime_t secs) return 0; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_time = { + "time", + PyInit_time, +}; diff --git a/third_party/python/Modules/unicodedata.c b/third_party/python/Modules/unicodedata.c index 28e62baf1..40e8c868b 100644 --- a/third_party/python/Modules/unicodedata.c +++ b/third_party/python/Modules/unicodedata.c @@ -7,6 +7,7 @@ #define PY_SSIZE_T_CLEAN #include "libc/fmt/fmt.h" #include "third_party/python/Include/floatobject.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/objimpl.h" @@ -1410,3 +1411,8 @@ c-basic-offset: 4 indent-tabs-mode: nil End: */ + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_unicodedata = { + "unicodedata", + PyInit_unicodedata, +}; diff --git a/third_party/python/Modules/winreparse.h b/third_party/python/Modules/winreparse.h index 7a2286737..2983e192b 100644 --- a/third_party/python/Modules/winreparse.h +++ b/third_party/python/Modules/winreparse.h @@ -1,55 +1,14 @@ -#ifndef Py_WINREPARSE_H -#define Py_WINREPARSE_H -/* clang-format off */ +#ifndef COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES_WINREPARSE_H_ +#define COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES_WINREPARSE_H_ +#include "libc/nt/struct/reparsedatabuffer.h" +#if !(__ASSEMBLER__ + __LINKER__ + 0) -#ifdef MS_WINDOWS -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* The following structure was copied from - http://msdn.microsoft.com/en-us/library/ff552012.aspx as the required - include km\ntifs.h isn't present in the Windows SDK (at least as included - with Visual Studio Express). Use unique names to avoid conflicting with - the structure as defined by Min GW. */ -typedef struct { - ULONG ReparseTag; - USHORT ReparseDataLength; - USHORT Reserved; - union { - struct { - USHORT SubstituteNameOffset; - USHORT SubstituteNameLength; - USHORT PrintNameOffset; - USHORT PrintNameLength; - ULONG Flags; - WCHAR PathBuffer[1]; - } SymbolicLinkReparseBuffer; - - struct { - USHORT SubstituteNameOffset; - USHORT SubstituteNameLength; - USHORT PrintNameOffset; - USHORT PrintNameLength; - WCHAR PathBuffer[1]; - } MountPointReparseBuffer; - - struct { - UCHAR DataBuffer[1]; - } GenericReparseBuffer; - }; -} _Py_REPARSE_DATA_BUFFER, *_Py_PREPARSE_DATA_BUFFER; +#define _Py_REPARSE_DATA_BUFFER struct NtReparseDataBuffer +#define _Py_PREPARSE_DATA_BUFFER struct NtReparseDataBuffer* #define _Py_REPARSE_DATA_BUFFER_HEADER_SIZE \ - FIELD_OFFSET(_Py_REPARSE_DATA_BUFFER, GenericReparseBuffer) -#define _Py_MAXIMUM_REPARSE_DATA_BUFFER_SIZE ( 16 * 1024 ) + offsetof(_Py_REPARSE_DATA_BUFFER, GenericReparseBuffer) +#define _Py_MAXIMUM_REPARSE_DATA_BUFFER_SIZE (16 * 1024) -#ifdef __cplusplus -} -#endif - -#endif /* MS_WINDOWS */ - -#endif /* !Py_WINREPARSE_H */ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES_WINREPARSE_H_ */ diff --git a/third_party/python/Modules/zipimport.c b/third_party/python/Modules/zipimport.c index 04875ec94..a6ed0ac9c 100644 --- a/third_party/python/Modules/zipimport.c +++ b/third_party/python/Modules/zipimport.c @@ -40,6 +40,10 @@ PYTHON_PROVIDE("zipimport.ZipImportError"); PYTHON_PROVIDE("zipimport._zip_directory_cache"); PYTHON_PROVIDE("zipimport.zipimporter"); +PYTHON_YOINK("encodings.ascii"); +PYTHON_YOINK("encodings.cp437"); +PYTHON_YOINK("encodings.utf_8"); + #define IS_SOURCE 0x0 #define IS_BYTECODE 0x1 #define IS_PACKAGE 0x2 @@ -1598,3 +1602,8 @@ PyInit_zipimport(void) return NULL; return mod; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_zipimport = { + "zipimport", + PyInit_zipimport, +}; diff --git a/third_party/python/Modules/zlibmodule.c b/third_party/python/Modules/zlibmodule.c index 020870305..fd85f5e8f 100644 --- a/third_party/python/Modules/zlibmodule.c +++ b/third_party/python/Modules/zlibmodule.c @@ -8,6 +8,7 @@ #include "third_party/python/Include/abstract.h" #include "third_party/python/Include/bytesobject.h" #include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/import.h" #include "third_party/python/Include/longobject.h" #include "third_party/python/Include/modsupport.h" #include "third_party/python/Include/objimpl.h" @@ -1454,3 +1455,8 @@ PyInit_zlib(void) return m; } + +_Section(".rodata.pytab.1") const struct _inittab _PyImport_Inittab_zlib = { + "zlib", + PyInit_zlib, +}; diff --git a/third_party/python/Objects/unicodeobject.c b/third_party/python/Objects/unicodeobject.c index 84600ad20..ec105116d 100644 --- a/third_party/python/Objects/unicodeobject.c +++ b/third_party/python/Objects/unicodeobject.c @@ -3281,11 +3281,6 @@ PyUnicode_Decode(const char *s, || strcmp(lower, "us_ascii") == 0) { return PyUnicode_DecodeASCII(s, size, errors); } - #ifdef MS_WINDOWS - else if (strcmp(lower, "mbcs") == 0) { - return PyUnicode_DecodeMBCS(s, size, errors); - } - #endif else if (strcmp(lower, "latin1") == 0 || strcmp(lower, "latin_1") == 0 || strcmp(lower, "iso_8859_1") == 0 @@ -7170,730 +7165,6 @@ PyUnicode_AsASCIIString(PyObject *unicode) return _PyUnicode_AsASCIIString(unicode, NULL); } -#ifdef MS_WINDOWS - -/* --- MBCS codecs for Windows -------------------------------------------- */ - -#if SIZEOF_INT < SIZEOF_SIZE_T -#define NEED_RETRY -#endif - -#ifndef WC_ERR_INVALID_CHARS -# define WC_ERR_INVALID_CHARS 0x0080 -#endif - -static const char* -code_page_name(UINT code_page, PyObject **obj) -{ - *obj = NULL; - if (code_page == CP_ACP) - return "mbcs"; - if (code_page == CP_UTF7) - return "CP_UTF7"; - if (code_page == CP_UTF8) - return "CP_UTF8"; - - *obj = PyBytes_FromFormat("cp%u", code_page); - if (*obj == NULL) - return NULL; - return PyBytes_AS_STRING(*obj); -} - -static DWORD -decode_code_page_flags(UINT code_page) -{ - if (code_page == CP_UTF7) { - /* The CP_UTF7 decoder only supports flags=0 */ - return 0; - } - else - return MB_ERR_INVALID_CHARS; -} - -/* - * Decode a byte string from a Windows code page into unicode object in strict - * mode. - * - * Returns consumed size if succeed, returns -2 on decode error, or raise an - * OSError and returns -1 on other error. - */ -static int -decode_code_page_strict(UINT code_page, - PyObject **v, - const char *in, - int insize) -{ - const DWORD flags = decode_code_page_flags(code_page); - wchar_t *out; - DWORD outsize; - - /* First get the size of the result */ - assert(insize > 0); - outsize = MultiByteToWideChar(code_page, flags, in, insize, NULL, 0); - if (outsize <= 0) - goto error; - - if (*v == NULL) { - /* Create unicode object */ - /* FIXME: don't use _PyUnicode_New(), but allocate a wchar_t* buffer */ - *v = (PyObject*)_PyUnicode_New(outsize); - if (*v == NULL) - return -1; - out = PyUnicode_AS_UNICODE(*v); - } - else { - /* Extend unicode object */ - Py_ssize_t n = PyUnicode_GET_SIZE(*v); - if (unicode_resize(v, n + outsize) < 0) - return -1; - out = PyUnicode_AS_UNICODE(*v) + n; - } - - /* Do the conversion */ - outsize = MultiByteToWideChar(code_page, flags, in, insize, out, outsize); - if (outsize <= 0) - goto error; - return insize; - -error: - if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION) - return -2; - PyErr_SetFromWindowsErr(0); - return -1; -} - -/* - * Decode a byte string from a code page into unicode object with an error - * handler. - * - * Returns consumed size if succeed, or raise an OSError or - * UnicodeDecodeError exception and returns -1 on error. - */ -static int -decode_code_page_errors(UINT code_page, - PyObject **v, - const char *in, const int size, - const char *errors, int final) -{ - const char *startin = in; - const char *endin = in + size; - const DWORD flags = decode_code_page_flags(code_page); - /* Ideally, we should get reason from FormatMessage. This is the Windows - 2000 English version of the message. */ - const char *reason = "No mapping for the Unicode character exists " - "in the target code page."; - /* each step cannot decode more than 1 character, but a character can be - represented as a surrogate pair */ - wchar_t buffer[2], *out; - int insize; - Py_ssize_t outsize; - PyObject *errorHandler = NULL; - PyObject *exc = NULL; - PyObject *encoding_obj = NULL; - const char *encoding; - DWORD err; - int ret = -1; - - assert(size > 0); - - encoding = code_page_name(code_page, &encoding_obj); - if (encoding == NULL) - return -1; - - if ((errors == NULL || strcmp(errors, "strict") == 0) && final) { - /* The last error was ERROR_NO_UNICODE_TRANSLATION, then we raise a - UnicodeDecodeError. */ - make_decode_exception(&exc, encoding, in, size, 0, 0, reason); - if (exc != NULL) { - PyCodec_StrictErrors(exc); - Py_CLEAR(exc); - } - goto error; - } - - if (*v == NULL) { - /* Create unicode object */ - if (size > PY_SSIZE_T_MAX / (Py_ssize_t)Py_ARRAY_LENGTH(buffer)) { - PyErr_NoMemory(); - goto error; - } - /* FIXME: don't use _PyUnicode_New(), but allocate a wchar_t* buffer */ - *v = (PyObject*)_PyUnicode_New(size * Py_ARRAY_LENGTH(buffer)); - if (*v == NULL) - goto error; - out = PyUnicode_AS_UNICODE(*v); - } - else { - /* Extend unicode object */ - Py_ssize_t n = PyUnicode_GET_SIZE(*v); - if (size > (PY_SSIZE_T_MAX - n) / (Py_ssize_t)Py_ARRAY_LENGTH(buffer)) { - PyErr_NoMemory(); - goto error; - } - if (unicode_resize(v, n + size * Py_ARRAY_LENGTH(buffer)) < 0) - goto error; - out = PyUnicode_AS_UNICODE(*v) + n; - } - - /* Decode the byte string character per character */ - while (in < endin) - { - /* Decode a character */ - insize = 1; - do - { - outsize = MultiByteToWideChar(code_page, flags, - in, insize, - buffer, Py_ARRAY_LENGTH(buffer)); - if (outsize > 0) - break; - err = GetLastError(); - if (err != ERROR_NO_UNICODE_TRANSLATION - && err != ERROR_INSUFFICIENT_BUFFER) - { - PyErr_SetFromWindowsErr(0); - goto error; - } - insize++; - } - /* 4=maximum length of a UTF-8 sequence */ - while (insize <= 4 && (in + insize) <= endin); - - if (outsize <= 0) { - Py_ssize_t startinpos, endinpos, outpos; - - /* last character in partial decode? */ - if (in + insize >= endin && !final) - break; - - startinpos = in - startin; - endinpos = startinpos + 1; - outpos = out - PyUnicode_AS_UNICODE(*v); - if (unicode_decode_call_errorhandler_wchar( - errors, &errorHandler, - encoding, reason, - &startin, &endin, &startinpos, &endinpos, &exc, &in, - v, &outpos)) - { - goto error; - } - out = PyUnicode_AS_UNICODE(*v) + outpos; - } - else { - in += insize; - memcpy(out, buffer, outsize * sizeof(wchar_t)); - out += outsize; - } - } - - /* write a NUL character at the end */ - *out = 0; - - /* Extend unicode object */ - outsize = out - PyUnicode_AS_UNICODE(*v); - assert(outsize <= PyUnicode_WSTR_LENGTH(*v)); - if (unicode_resize(v, outsize) < 0) - goto error; - /* (in - startin) <= size and size is an int */ - ret = Py_SAFE_DOWNCAST(in - startin, Py_ssize_t, int); - -error: - Py_XDECREF(encoding_obj); - Py_XDECREF(errorHandler); - Py_XDECREF(exc); - return ret; -} - -static PyObject * -decode_code_page_stateful(int code_page, - const char *s, Py_ssize_t size, - const char *errors, Py_ssize_t *consumed) -{ - PyObject *v = NULL; - int chunk_size, final, converted, done; - - if (code_page < 0) { - PyErr_SetString(PyExc_ValueError, "invalid code page number"); - return NULL; - } - if (size < 0) { - PyErr_BadInternalCall(); - return NULL; - } - - if (consumed) - *consumed = 0; - - do - { -#ifdef NEED_RETRY - if (size > INT_MAX) { - chunk_size = INT_MAX; - final = 0; - done = 0; - } - else -#endif - { - chunk_size = (int)size; - final = (consumed == NULL); - done = 1; - } - - if (chunk_size == 0 && done) { - if (v != NULL) - break; - _Py_RETURN_UNICODE_EMPTY(); - } - - converted = decode_code_page_strict(code_page, &v, - s, chunk_size); - if (converted == -2) - converted = decode_code_page_errors(code_page, &v, - s, chunk_size, - errors, final); - assert(converted != 0 || done); - - if (converted < 0) { - Py_XDECREF(v); - return NULL; - } - - if (consumed) - *consumed += converted; - - s += converted; - size -= converted; - } while (!done); - - return unicode_result(v); -} - -PyObject * -PyUnicode_DecodeCodePageStateful(int code_page, - const char *s, - Py_ssize_t size, - const char *errors, - Py_ssize_t *consumed) -{ - return decode_code_page_stateful(code_page, s, size, errors, consumed); -} - -PyObject * -PyUnicode_DecodeMBCSStateful(const char *s, - Py_ssize_t size, - const char *errors, - Py_ssize_t *consumed) -{ - return decode_code_page_stateful(CP_ACP, s, size, errors, consumed); -} - -PyObject * -PyUnicode_DecodeMBCS(const char *s, - Py_ssize_t size, - const char *errors) -{ - return PyUnicode_DecodeMBCSStateful(s, size, errors, NULL); -} - -static DWORD -encode_code_page_flags(UINT code_page, const char *errors) -{ - if (code_page == CP_UTF8) { - return WC_ERR_INVALID_CHARS; - } - else if (code_page == CP_UTF7) { - /* CP_UTF7 only supports flags=0 */ - return 0; - } - else { - if (errors != NULL && strcmp(errors, "replace") == 0) - return 0; - else - return WC_NO_BEST_FIT_CHARS; - } -} - -/* - * Encode a Unicode string to a Windows code page into a byte string in strict - * mode. - * - * Returns consumed characters if succeed, returns -2 on encode error, or raise - * an OSError and returns -1 on other error. - */ -static int -encode_code_page_strict(UINT code_page, PyObject **outbytes, - PyObject *unicode, Py_ssize_t offset, int len, - const char* errors) -{ - BOOL usedDefaultChar = FALSE; - BOOL *pusedDefaultChar = &usedDefaultChar; - int outsize; - wchar_t *p; - Py_ssize_t size; - const DWORD flags = encode_code_page_flags(code_page, NULL); - char *out; - /* Create a substring so that we can get the UTF-16 representation - of just the slice under consideration. */ - PyObject *substring; - - assert(len > 0); - - if (code_page != CP_UTF8 && code_page != CP_UTF7) - pusedDefaultChar = &usedDefaultChar; - else - pusedDefaultChar = NULL; - - substring = PyUnicode_Substring(unicode, offset, offset+len); - if (substring == NULL) - return -1; - p = PyUnicode_AsUnicodeAndSize(substring, &size); - if (p == NULL) { - Py_DECREF(substring); - return -1; - } - assert(size <= INT_MAX); - - /* First get the size of the result */ - outsize = WideCharToMultiByte(code_page, flags, - p, (int)size, - NULL, 0, - NULL, pusedDefaultChar); - if (outsize <= 0) - goto error; - /* If we used a default char, then we failed! */ - if (pusedDefaultChar && *pusedDefaultChar) { - Py_DECREF(substring); - return -2; - } - - if (*outbytes == NULL) { - /* Create string object */ - *outbytes = PyBytes_FromStringAndSize(NULL, outsize); - if (*outbytes == NULL) { - Py_DECREF(substring); - return -1; - } - out = PyBytes_AS_STRING(*outbytes); - } - else { - /* Extend string object */ - const Py_ssize_t n = PyBytes_Size(*outbytes); - if (outsize > PY_SSIZE_T_MAX - n) { - PyErr_NoMemory(); - Py_DECREF(substring); - return -1; - } - if (_PyBytes_Resize(outbytes, n + outsize) < 0) { - Py_DECREF(substring); - return -1; - } - out = PyBytes_AS_STRING(*outbytes) + n; - } - - /* Do the conversion */ - outsize = WideCharToMultiByte(code_page, flags, - p, (int)size, - out, outsize, - NULL, pusedDefaultChar); - Py_CLEAR(substring); - if (outsize <= 0) - goto error; - if (pusedDefaultChar && *pusedDefaultChar) - return -2; - return 0; - -error: - Py_XDECREF(substring); - if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION) - return -2; - PyErr_SetFromWindowsErr(0); - return -1; -} - -/* - * Encode a Unicode string to a Windows code page into a byte string using an - * error handler. - * - * Returns consumed characters if succeed, or raise an OSError and returns - * -1 on other error. - */ -static int -encode_code_page_errors(UINT code_page, PyObject **outbytes, - PyObject *unicode, Py_ssize_t unicode_offset, - Py_ssize_t insize, const char* errors) -{ - const DWORD flags = encode_code_page_flags(code_page, errors); - Py_ssize_t pos = unicode_offset; - Py_ssize_t endin = unicode_offset + insize; - /* Ideally, we should get reason from FormatMessage. This is the Windows - 2000 English version of the message. */ - const char *reason = "invalid character"; - /* 4=maximum length of a UTF-8 sequence */ - char buffer[4]; - BOOL usedDefaultChar = FALSE, *pusedDefaultChar; - Py_ssize_t outsize; - char *out; - PyObject *errorHandler = NULL; - PyObject *exc = NULL; - PyObject *encoding_obj = NULL; - const char *encoding; - Py_ssize_t newpos, newoutsize; - PyObject *rep; - int ret = -1; - - assert(insize > 0); - - encoding = code_page_name(code_page, &encoding_obj); - if (encoding == NULL) - return -1; - - if (errors == NULL || strcmp(errors, "strict") == 0) { - /* The last error was ERROR_NO_UNICODE_TRANSLATION, - then we raise a UnicodeEncodeError. */ - make_encode_exception(&exc, encoding, unicode, 0, 0, reason); - if (exc != NULL) { - PyCodec_StrictErrors(exc); - Py_DECREF(exc); - } - Py_XDECREF(encoding_obj); - return -1; - } - - if (code_page != CP_UTF8 && code_page != CP_UTF7) - pusedDefaultChar = &usedDefaultChar; - else - pusedDefaultChar = NULL; - - if (Py_ARRAY_LENGTH(buffer) > PY_SSIZE_T_MAX / insize) { - PyErr_NoMemory(); - goto error; - } - outsize = insize * Py_ARRAY_LENGTH(buffer); - - if (*outbytes == NULL) { - /* Create string object */ - *outbytes = PyBytes_FromStringAndSize(NULL, outsize); - if (*outbytes == NULL) - goto error; - out = PyBytes_AS_STRING(*outbytes); - } - else { - /* Extend string object */ - Py_ssize_t n = PyBytes_Size(*outbytes); - if (n > PY_SSIZE_T_MAX - outsize) { - PyErr_NoMemory(); - goto error; - } - if (_PyBytes_Resize(outbytes, n + outsize) < 0) - goto error; - out = PyBytes_AS_STRING(*outbytes) + n; - } - - /* Encode the string character per character */ - while (pos < endin) - { - Py_UCS4 ch = PyUnicode_READ_CHAR(unicode, pos); - wchar_t chars[2]; - int charsize; - if (ch < 0x10000) { - chars[0] = (wchar_t)ch; - charsize = 1; - } - else { - chars[0] = Py_UNICODE_HIGH_SURROGATE(ch); - chars[1] = Py_UNICODE_LOW_SURROGATE(ch); - charsize = 2; - } - - outsize = WideCharToMultiByte(code_page, flags, - chars, charsize, - buffer, Py_ARRAY_LENGTH(buffer), - NULL, pusedDefaultChar); - if (outsize > 0) { - if (pusedDefaultChar == NULL || !(*pusedDefaultChar)) - { - pos++; - memcpy(out, buffer, outsize); - out += outsize; - continue; - } - } - else if (GetLastError() != ERROR_NO_UNICODE_TRANSLATION) { - PyErr_SetFromWindowsErr(0); - goto error; - } - - rep = unicode_encode_call_errorhandler( - errors, &errorHandler, encoding, reason, - unicode, &exc, - pos, pos + 1, &newpos); - if (rep == NULL) - goto error; - pos = newpos; - - if (PyBytes_Check(rep)) { - outsize = PyBytes_GET_SIZE(rep); - if (outsize != 1) { - Py_ssize_t offset = out - PyBytes_AS_STRING(*outbytes); - newoutsize = PyBytes_GET_SIZE(*outbytes) + (outsize - 1); - if (_PyBytes_Resize(outbytes, newoutsize) < 0) { - Py_DECREF(rep); - goto error; - } - out = PyBytes_AS_STRING(*outbytes) + offset; - } - memcpy(out, PyBytes_AS_STRING(rep), outsize); - out += outsize; - } - else { - Py_ssize_t i; - enum PyUnicode_Kind kind; - void *data; - - if (PyUnicode_READY(rep) == -1) { - Py_DECREF(rep); - goto error; - } - - outsize = PyUnicode_GET_LENGTH(rep); - if (outsize != 1) { - Py_ssize_t offset = out - PyBytes_AS_STRING(*outbytes); - newoutsize = PyBytes_GET_SIZE(*outbytes) + (outsize - 1); - if (_PyBytes_Resize(outbytes, newoutsize) < 0) { - Py_DECREF(rep); - goto error; - } - out = PyBytes_AS_STRING(*outbytes) + offset; - } - kind = PyUnicode_KIND(rep); - data = PyUnicode_DATA(rep); - for (i=0; i < outsize; i++) { - Py_UCS4 ch = PyUnicode_READ(kind, data, i); - if (ch > 127) { - raise_encode_exception(&exc, - encoding, unicode, - pos, pos + 1, - "unable to encode error handler result to ASCII"); - Py_DECREF(rep); - goto error; - } - *out = (unsigned char)ch; - out++; - } - } - Py_DECREF(rep); - } - /* write a NUL byte */ - *out = 0; - outsize = out - PyBytes_AS_STRING(*outbytes); - assert(outsize <= PyBytes_GET_SIZE(*outbytes)); - if (_PyBytes_Resize(outbytes, outsize) < 0) - goto error; - ret = 0; - -error: - Py_XDECREF(encoding_obj); - Py_XDECREF(errorHandler); - Py_XDECREF(exc); - return ret; -} - -static PyObject * -encode_code_page(int code_page, - PyObject *unicode, - const char *errors) -{ - Py_ssize_t len; - PyObject *outbytes = NULL; - Py_ssize_t offset; - int chunk_len, ret, done; - - if (!PyUnicode_Check(unicode)) { - PyErr_BadArgument(); - return NULL; - } - - if (PyUnicode_READY(unicode) == -1) - return NULL; - len = PyUnicode_GET_LENGTH(unicode); - - if (code_page < 0) { - PyErr_SetString(PyExc_ValueError, "invalid code page number"); - return NULL; - } - - if (len == 0) - return PyBytes_FromStringAndSize(NULL, 0); - - offset = 0; - do - { -#ifdef NEED_RETRY - /* UTF-16 encoding may double the size, so use only INT_MAX/2 - chunks. */ - if (len > INT_MAX/2) { - chunk_len = INT_MAX/2; - done = 0; - } - else -#endif - { - chunk_len = (int)len; - done = 1; - } - - ret = encode_code_page_strict(code_page, &outbytes, - unicode, offset, chunk_len, - errors); - if (ret == -2) - ret = encode_code_page_errors(code_page, &outbytes, - unicode, offset, - chunk_len, errors); - if (ret < 0) { - Py_XDECREF(outbytes); - return NULL; - } - - offset += chunk_len; - len -= chunk_len; - } while (!done); - - return outbytes; -} - -PyObject * -PyUnicode_EncodeMBCS(const Py_UNICODE *p, - Py_ssize_t size, - const char *errors) -{ - PyObject *unicode, *res; - unicode = PyUnicode_FromUnicode(p, size); - if (unicode == NULL) - return NULL; - res = encode_code_page(CP_ACP, unicode, errors); - Py_DECREF(unicode); - return res; -} - -PyObject * -PyUnicode_EncodeCodePage(int code_page, - PyObject *unicode, - const char *errors) -{ - return encode_code_page(code_page, unicode, errors); -} - -PyObject * -PyUnicode_AsMBCSString(PyObject *unicode) -{ - return PyUnicode_EncodeCodePage(CP_ACP, unicode, NULL); -} - -#undef NEED_RETRY - -#endif /* MS_WINDOWS */ - /* --- Character Mapping Codec -------------------------------------------- */ static int diff --git a/third_party/python/Programs/hello.c b/third_party/python/Programs/hello.c new file mode 100644 index 000000000..1e79e2527 --- /dev/null +++ b/third_party/python/Programs/hello.c @@ -0,0 +1,2 @@ +#define LAUNCH "hello" +#include "third_party/python/Programs/launch.c" diff --git a/third_party/python/Programs/httpserver.c b/third_party/python/Programs/httpserver.c index c8d21862c..3f2d95868 100644 --- a/third_party/python/Programs/httpserver.c +++ b/third_party/python/Programs/httpserver.c @@ -1,2 +1,2 @@ -#include "third_party/python/Programs/repl.c" -PYTHON_YOINK("http.server"); +#define LAUNCH "http.server" +#include "third_party/python/Programs/launch.c" diff --git a/third_party/python/Programs/launch.c b/third_party/python/Programs/launch.c new file mode 100644 index 000000000..c36403427 --- /dev/null +++ b/third_party/python/Programs/launch.c @@ -0,0 +1,143 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:4;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=4 sts=4 sw=4 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Python 3 │ +│ https://docs.python.org/3/license.html │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/bits/bits.h" +#include "libc/bits/safemacros.internal.h" +#include "libc/calls/calls.h" +#include "libc/dce.h" +#include "libc/errno.h" +#include "libc/log/check.h" +#include "libc/log/log.h" +#include "libc/mem/mem.h" +#include "libc/nexgen32e/rdtsc.h" +#include "libc/runtime/gc.internal.h" +#include "libc/runtime/runtime.h" +#include "libc/runtime/symbols.internal.h" +#include "libc/stdio/stdio.h" +#include "libc/str/str.h" +#include "libc/sysv/consts/fileno.h" +#include "libc/sysv/consts/sig.h" +#include "libc/unicode/locale.h" +#include "libc/x/x.h" +#include "libc/zip.h" +#include "third_party/linenoise/linenoise.h" +#include "third_party/python/Include/abstract.h" +#include "third_party/python/Include/ceval.h" +#include "third_party/python/Include/dictobject.h" +#include "third_party/python/Include/fileutils.h" +#include "third_party/python/Include/funcobject.h" +#include "third_party/python/Include/import.h" +#include "third_party/python/Include/listobject.h" +#include "third_party/python/Include/modsupport.h" +#include "third_party/python/Include/moduleobject.h" +#include "third_party/python/Include/object.h" +#include "third_party/python/Include/pydebug.h" +#include "third_party/python/Include/pyerrors.h" +#include "third_party/python/Include/pylifecycle.h" +#include "third_party/python/Include/pymem.h" +#include "third_party/python/Include/pyport.h" +#include "third_party/python/Include/pythonrun.h" +#include "third_party/python/Include/sysmodule.h" +#include "third_party/python/Include/unicodeobject.h" +#include "third_party/python/Include/yoink.h" +/* clang-format off */ + +#define _L(x) L##x +#define L(x) _L(x) + +PYTHON_YOINK(LAUNCH); + +PYTHON_YOINK("_bootlocale"); +PYTHON_YOINK("_locale"); +PYTHON_YOINK("encodings.aliases"); +PYTHON_YOINK("encodings.latin_1"); +PYTHON_YOINK("encodings.utf_8"); +PYTHON_YOINK("launchpy"); + +const struct _frozen *PyImport_FrozenModules = _PyImport_FrozenModules; +struct _inittab *PyImport_Inittab = _PyImport_Inittab; + +static int LaunchModule(wchar_t *modname) +{ + PyObject *module, *runpy, *runmodule, *runargs, *result; + runpy = PyImport_ImportModule("launchpy"); + if (runpy == NULL) { + fprintf(stderr, "Could not import launchpy module\n"); + PyErr_Print(); + return -1; + } + runmodule = PyObject_GetAttrString(runpy, "run_module_as_main"); + if (runmodule == NULL) { + fprintf(stderr, "Could not access launchpy.run_module_as_main\n"); + PyErr_Print(); + Py_DECREF(runpy); + return -1; + } + module = PyUnicode_FromWideChar(modname, wcslen(modname)); + if (module == NULL) { + fprintf(stderr, "Could not convert module name to unicode\n"); + PyErr_Print(); + Py_DECREF(runpy); + Py_DECREF(runmodule); + return -1; + } + runargs = Py_BuildValue("(O)", module); + if (runargs == NULL) { + fprintf(stderr, + "Could not create arguments for runpy._run_module_as_main\n"); + PyErr_Print(); + Py_DECREF(runpy); + Py_DECREF(runmodule); + Py_DECREF(module); + return -1; + } + result = PyObject_Call(runmodule, runargs, NULL); + if (result == NULL) { + PyErr_Print(); + } + Py_DECREF(runpy); + Py_DECREF(runmodule); + Py_DECREF(module); + Py_DECREF(runargs); + if (result == NULL) { + return -1; + } + Py_DECREF(result); + return 0; +} + +int +main(int argc, char **argv) +{ + int i, res; + char *oldloc; + wchar_t **argv_copy; + wchar_t **argv_copy2; + _PyMem_SetupAllocators("malloc"); + argv_copy = gc(malloc(sizeof(wchar_t*) * (argc+1))); + argv_copy2 = gc(malloc(sizeof(wchar_t*) * (argc+1))); + oldloc = _PyMem_RawStrdup(setlocale(LC_ALL, NULL)); + setlocale(LC_ALL, ""); + for (i = 0; i < argc; i++) { + argv_copy2[i] = argv_copy[i] = gc(utf8toutf32(argv[i], -1, 0)); + } + argv_copy2[argc] = argv_copy[argc] = NULL; + setlocale(LC_ALL, oldloc); + PyMem_RawFree(oldloc); + _PyRandom_Init(); + Py_FrozenFlag++; + Py_NoSiteFlag++; + /* Py_VerboseFlag++; */ + Py_NoUserSiteDirectory++; + Py_IgnoreEnvironmentFlag++; + Py_DontWriteBytecodeFlag++; + Py_Initialize(); + Py_LimitedPath(); + PySys_SetArgvEx(argc, argv_copy, 0); + res = LaunchModule(L(LAUNCH)) != 0; + _PyMem_SetupAllocators("malloc"); + return res; +} diff --git a/third_party/python/Programs/python.c b/third_party/python/Programs/python.c index cae2be978..7a07480dd 100644 --- a/third_party/python/Programs/python.c +++ b/third_party/python/Programs/python.c @@ -131,20 +131,15 @@ PYTHON_YOINK("weakref"); PYTHON_YOINK("webbrowser"); PYTHON_YOINK("xdrlib"); -#if !IsTiny() PYTHON_YOINK("aifc"); PYTHON_YOINK("wave"); PYTHON_YOINK("sunau"); -#endif -#if !IsTiny() PYTHON_YOINK("dis"); PYTHON_YOINK("codeop"); PYTHON_YOINK("compileall"); PYTHON_YOINK("py_compile"); -#endif -#if !IsTiny() PYTHON_YOINK("cgi"); PYTHON_YOINK("pdb"); PYTHON_YOINK("cgitb"); @@ -154,9 +149,7 @@ PYTHON_YOINK("profile"); PYTHON_YOINK("inspect"); PYTHON_YOINK("cProfile"); PYTHON_YOINK("tracemalloc"); -#endif -#if !IsTiny() PYTHON_YOINK("bz2"); PYTHON_YOINK("ssl"); PYTHON_YOINK("gzip"); @@ -169,7 +162,6 @@ PYTHON_YOINK("zipfile"); PYTHON_YOINK("telnetlib"); PYTHON_YOINK("antigravity"); PYTHON_YOINK("rlcompleter"); -#endif PYTHON_YOINK("collections"); PYTHON_YOINK("collections.abc"); @@ -246,20 +238,15 @@ PYTHON_YOINK("wsgiref.simple_server"); PYTHON_YOINK("wsgiref.util"); PYTHON_YOINK("wsgiref.validate"); -#if !IsTiny() PYTHON_YOINK("sqlite3"); PYTHON_YOINK("sqlite3.dbapi2"); PYTHON_YOINK("sqlite3.dump"); -#endif -#if !IsTiny() PYTHON_YOINK("dbm"); PYTHON_YOINK("dbm.dumb"); PYTHON_YOINK("dbm.gnu"); PYTHON_YOINK("dbm.ndbm"); -#endif -#if !IsTiny() PYTHON_YOINK("xml"); PYTHON_YOINK("xml.dom.NodeFilter"); PYTHON_YOINK("xml.dom"); @@ -285,9 +272,7 @@ PYTHON_YOINK("xml.sax.xmlreader"); PYTHON_YOINK("xmlrpc"); PYTHON_YOINK("xmlrpc.client"); PYTHON_YOINK("xmlrpc.server"); -#endif -#if !IsTiny() PYTHON_YOINK("multiprocessing"); PYTHON_YOINK("multiprocessing.connection"); PYTHON_YOINK("multiprocessing.context"); @@ -310,9 +295,7 @@ PYTHON_YOINK("multiprocessing.sharedctypes"); PYTHON_YOINK("multiprocessing.spawn"); PYTHON_YOINK("multiprocessing.synchronize"); PYTHON_YOINK("multiprocessing.util"); -#endif -#if !IsTiny() PYTHON_YOINK("unittest"); PYTHON_YOINK("unittest.__main__"); PYTHON_YOINK("unittest.case"); @@ -324,9 +307,7 @@ PYTHON_YOINK("unittest.runner"); PYTHON_YOINK("unittest.signals"); PYTHON_YOINK("unittest.suite"); PYTHON_YOINK("unittest.util"); -#endif -#if !IsTiny() PYTHON_YOINK("venv"); PYTHON_YOINK("venv.__main__"); STATIC_YOINK(".python/venv/scripts/common/activate"); @@ -441,7 +422,6 @@ PYTHON_YOINK("msilib"); PYTHON_YOINK("msilib.schema"); PYTHON_YOINK("msilib.sequence"); PYTHON_YOINK("msilib.text"); -#endif PYTHON_YOINK("encodings"); PYTHON_YOINK("encodings.aliases"); @@ -464,7 +444,6 @@ PYTHON_YOINK("encodings.base64_codec"); PYTHON_YOINK("encodings.unicode_escape"); PYTHON_YOINK("encodings.unicode_internal"); PYTHON_YOINK("encodings.raw_unicode_escape"); -#if !IsTiny() PYTHON_YOINK("encodings.zlib_codec"); PYTHON_YOINK("encodings.big5"); PYTHON_YOINK("encodings.big5hkscs"); @@ -569,9 +548,7 @@ PYTHON_YOINK("encodings.shift_jis_2004"); PYTHON_YOINK("encodings.shift_jisx0213"); PYTHON_YOINK("encodings.tis_620"); PYTHON_YOINK("encodings.utf_7"); -#endif -#if !IsTiny() PYTHON_YOINK("smtpd"); PYTHON_YOINK("poplib"); PYTHON_YOINK("imaplib"); @@ -579,7 +556,6 @@ PYTHON_YOINK("mailbox"); PYTHON_YOINK("mailcap"); PYTHON_YOINK("smtplib"); PYTHON_YOINK("nntplib"); -#endif #ifdef WITH_THREAD PYTHON_YOINK("asynchat"); diff --git a/third_party/python/Python/importlib_external.inc b/third_party/python/Python/importlib_external.inc index 6f4867050..b4320d2ba 100644 --- a/third_party/python/Python/importlib_external.inc +++ b/third_party/python/Python/importlib_external.inc @@ -2289,7 +2289,7 @@ const unsigned char _Py_M__importlib_external[] = { 0,0,0,0,0,0,0,3,0,0,0,3,0,0,0,67, 0,0,0,115,38,0,0,0,116,0,116,1,106,2,131,0, 102,2,125,0,116,3,116,4,102,2,125,1,116,5,116,6, - 102,2,125,2,124,0,124,2,124,1,103,3,83,0,41,1, + 102,2,125,2,124,2,124,0,124,1,103,3,83,0,41,1, 122,95,82,101,116,117,114,110,115,32,97,32,108,105,115,116, 32,111,102,32,102,105,108,101,45,98,97,115,101,100,32,109, 111,100,117,108,101,32,108,111,97,100,101,114,115,46,10,10, diff --git a/third_party/python/Python/pylifecycle.c b/third_party/python/Python/pylifecycle.c index f86fc6fe8..59e73b74f 100644 --- a/third_party/python/Python/pylifecycle.c +++ b/third_party/python/Python/pylifecycle.c @@ -320,20 +320,19 @@ import_init(PyInterpreterState *interp, PyObject *sysmod) } Py_DECREF(value); Py_DECREF(impmod); - /* just add /zip/.python/ to sys.path */ /* _PyImportZip_Init(); */ - PyImport_ImportModule("_codecs"); - PyImport_ImportModule("_collections"); - PyImport_ImportModule("_functools"); - PyImport_ImportModule("_heapq"); - PyImport_ImportModule("_locale"); - PyImport_ImportModule("_operator"); - PyImport_ImportModule("_signal"); - PyImport_ImportModule("_sre"); - PyImport_ImportModule("_stat"); - PyImport_ImportModule("errno"); - PyImport_ImportModule("itertools"); + /* PyImport_ImportModule("_codecs"); */ + /* PyImport_ImportModule("_collections"); */ + /* PyImport_ImportModule("_functools"); */ + /* PyImport_ImportModule("_heapq"); */ + /* PyImport_ImportModule("_locale"); */ + /* PyImport_ImportModule("_operator"); */ + /* PyImport_ImportModule("_signal"); */ + /* PyImport_ImportModule("_sre"); */ + /* PyImport_ImportModule("_stat"); */ + /* PyImport_ImportModule("errno"); */ + /* PyImport_ImportModule("itertools"); */ } diff --git a/third_party/python/pycomp.c b/third_party/python/pycomp.c index 2cd1650cf..3ad52e844 100644 --- a/third_party/python/pycomp.c +++ b/third_party/python/pycomp.c @@ -38,6 +38,8 @@ #include "third_party/python/Include/pylifecycle.h" #include "third_party/python/Include/pymacro.h" #include "third_party/python/Include/pythonrun.h" +#include "third_party/python/Include/ucnhash.h" +#include "third_party/python/Include/yoink.h" #include "tool/build/lib/stripcomponents.h" /* clang-format off */ @@ -120,6 +122,7 @@ main(int argc, char *argv[]) Py_NoSiteFlag++; Py_IgnoreEnvironmentFlag++; Py_FrozenFlag++; + /* Py_VerboseFlag++; */ Py_SetProgramName(gc(utf8toutf32(argv[0], -1, 0))); _Py_InitializeEx_Private(1, 0); name = gc(xjoinpaths("/zip/.python", StripComponents(inpath, 3))); diff --git a/third_party/python/pyconfig.h b/third_party/python/pyconfig.h index 0cbdd27e7..3fecdad33 100644 --- a/third_party/python/pyconfig.h +++ b/third_party/python/pyconfig.h @@ -1132,5 +1132,8 @@ #define SELECT_USES_HEAP 1 #define OPENSSL_NO_SCRYPT +#define OPENSSL_NO_COMP + +#define HAVE_LANGINFO_H #endif /*Py_PYCONFIG_H*/ diff --git a/third_party/python/pyobj.c b/third_party/python/pyobj.c index a1788e1ee..bf288e109 100644 --- a/third_party/python/pyobj.c +++ b/third_party/python/pyobj.c @@ -75,8 +75,10 @@ FLAGS\n\ -h help\n\ \n" -const char *const kIgnoredModules[] = /* sorted */ { +/* const struct _frozen *PyImport_FrozenModules = _PyImport_FrozenModules; */ +/* struct _inittab *PyImport_Inittab = _PyImport_Inittab; */ +const char *const kIgnoredModules[] = /* sorted */ { "__main__", /* todo? */ "_dummy_threading", /* evil code */ "_dummy_threading.Thread", @@ -200,7 +202,6 @@ const char *const kIgnoredModules[] = /* sorted */ { "test.libregrtest.main", "xml.dom", "xml.sax", - }; static bool binonly; diff --git a/third_party/python/python.mk b/third_party/python/python.mk index 4ed7651ec..e8a785439 100644 --- a/third_party/python/python.mk +++ b/third_party/python/python.mk @@ -27,6 +27,7 @@ THIRD_PARTY_PYTHON_COMS = \ o/$(MODE)/third_party/python/pyobj.com \ o/$(MODE)/third_party/python/pycomp.com \ o/$(MODE)/third_party/python/repl.com \ + o/$(MODE)/third_party/python/hello.com \ o/$(MODE)/third_party/python/httpserver.com \ o/$(MODE)/third_party/python/pythontester.com @@ -298,6 +299,7 @@ THIRD_PARTY_PYTHON_INCS = \ third_party/python/Modules/clinic/pwdmodule.inc \ third_party/python/Modules/clinic/audioop.inc \ third_party/python/Modules/clinic/sha256module.inc \ + third_party/python/Modules/clinic/_hashmbedtls.inc \ third_party/python/Modules/unicodedata_db.inc THIRD_PARTY_PYTHON_STAGE1_A_SRCS = \ @@ -401,10 +403,12 @@ THIRD_PARTY_PYTHON_STAGE1_A_SRCS = \ third_party/python/Python/symtable.c \ third_party/python/Parser/listnode.c \ third_party/python/Python/sysmodule.c \ + third_party/python/Modules/unicodedata.c \ + third_party/python/Objects/unicodetonumeric.c \ third_party/python/Python/traceback.c THIRD_PARTY_PYTHON_STAGE2_A_SRCS = \ - third_party/python/Modules/_hashopenssl.c \ + third_party/python/Modules/_hashmbedtls.c \ third_party/python/Objects/fromfd.c \ third_party/python/Modules/_bisectmodule.c \ third_party/python/Modules/_bz2module.c \ @@ -511,11 +515,9 @@ THIRD_PARTY_PYTHON_STAGE2_A_SRCS = \ third_party/python/Modules/syslogmodule.c \ third_party/python/Modules/termios.c \ third_party/python/Modules/timemodule.c \ - third_party/python/Modules/unicodedata.c \ third_party/python/Modules/zipimport.c \ third_party/python/Modules/zlibmodule.c \ third_party/python/Objects/accu.c \ - third_party/python/Objects/unicodetonumeric.c \ third_party/python/Objects/weakrefobject.c \ third_party/python/Parser/bitset.c \ third_party/python/Parser/firstsets.c \ @@ -1208,12 +1210,14 @@ THIRD_PARTY_PYTHON_STDLIB_PYS = \ third_party/python/Lib/re.py \ third_party/python/Lib/reprlib.py \ third_party/python/Lib/runpy.py \ + third_party/python/Lib/launchpy.py \ third_party/python/Lib/sched.py \ third_party/python/Lib/secrets.py \ third_party/python/Lib/selectors.py \ third_party/python/Lib/shelve.py \ third_party/python/Lib/shlex.py \ third_party/python/Lib/shutil.py \ + third_party/python/Lib/hello.py \ third_party/python/Lib/signal.py \ third_party/python/Lib/site.py \ third_party/python/Lib/smtpd.py \ @@ -1922,6 +1926,16 @@ o/$(MODE)/third_party/python/httpserver.com.dbg: \ $(APE) @$(APELINK) +o/$(MODE)/third_party/python/hello.com.dbg: \ + $(THIRD_PARTY_PYTHON_STAGE1) \ + $(THIRD_PARTY_PYTHON_STAGE1_A).pkg \ + $(THIRD_PARTY_PYTHON_STAGE2) \ + $(THIRD_PARTY_PYTHON_STAGE2_A).pkg \ + o/$(MODE)/third_party/python/Programs/hello.o \ + $(CRT) \ + $(APE) + @$(APELINK) + o/$(MODE)/third_party/python/pythontester.com.dbg: \ $(THIRD_PARTY_PYTHON_STAGE1) \ $(THIRD_PARTY_PYTHON_STAGE1_A).pkg \ @@ -2035,8 +2049,12 @@ THIRD_PARTY_PYTHON_SRCS = \ $(foreach x,$(THIRD_PARTY_PYTHON_ARTIFACTS),$($(x)_SRCS)) \ third_party/python/pyobj.c \ third_party/python/pycomp.c \ + third_party/python/Programs/repl.c \ + third_party/python/Programs/hello.c \ + third_party/python/Programs/launch.c \ third_party/python/Programs/freeze.c \ third_party/python/Programs/python.c \ + third_party/python/Programs/httpserver.c \ third_party/python/Programs/pythontester.c #$(THIRD_PARTY_PYTHON_OBJS): \ diff --git a/tool/net/redbean.c b/tool/net/redbean.c index b4280b970..8c88078b6 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -586,7 +586,8 @@ static void InternCertificate(mbedtls_x509_crt *cert, mbedtls_x509_crt *prev) { if (cert->next) InternCertificate(cert->next, cert); if (prev) { if (mbedtls_x509_crt_check_parent(prev, cert, 1)) { - DEBUGF("(ssl) unbundling %`'s from %`'s", gc(FormatX509Name(&prev->subject)), + DEBUGF("(ssl) unbundling %`'s from %`'s", + gc(FormatX509Name(&prev->subject)), gc(FormatX509Name(&cert->subject))); prev->next = 0; } else if ((r = mbedtls_x509_crt_check_signature(prev, cert, 0))) { @@ -598,14 +599,16 @@ static void InternCertificate(mbedtls_x509_crt *cert, mbedtls_x509_crt *prev) { if (mbedtls_x509_time_is_past(&cert->valid_to)) { WARNF("(ssl) certificate is expired", gc(FormatX509Name(&cert->subject))); } else if (mbedtls_x509_time_is_future(&cert->valid_from)) { - WARNF("(ssl) certificate is from the future", gc(FormatX509Name(&cert->subject))); + WARNF("(ssl) certificate is from the future", + gc(FormatX509Name(&cert->subject))); } for (i = 0; i < certs.n; ++i) { if (!certs.p[i].cert) continue; if (mbedtls_pk_get_type(&cert->pk) == mbedtls_pk_get_type(&certs.p[i].cert->pk) && !mbedtls_x509_name_cmp(&cert->subject, &certs.p[i].cert->subject)) { - VERBOSEF("(ssl) %s %`'s is already loaded", mbedtls_pk_get_name(&cert->pk), + VERBOSEF("(ssl) %s %`'s is already loaded", + mbedtls_pk_get_name(&cert->pk), gc(FormatX509Name(&cert->subject))); return; } @@ -1100,8 +1103,8 @@ static void ReportWorkerExit(int pid, int ws) { if (WIFEXITED(ws)) { if (WEXITSTATUS(ws)) { LockInc(&shared->c.failedchildren); - WARNF("(stat) %d exited with %d (%,d workers remain)", pid, WEXITSTATUS(ws), - shared->workers); + WARNF("(stat) %d exited with %d (%,d workers remain)", pid, + WEXITSTATUS(ws), shared->workers); } else { DEBUGF("(stat) %d exited (%,d workers remain)", pid, shared->workers); } @@ -1396,8 +1399,8 @@ static bool TlsRouteFind(mbedtls_pk_type_t type, mbedtls_ssl_context *ssl, CertHasCommonName(certs.p[i].cert, host, size))) { CHECK_EQ( 0, mbedtls_ssl_set_hs_own_cert(ssl, certs.p[i].cert, certs.p[i].key)); - DEBUGF("(ssl) TlsRoute(%s, %`'.*s) %s %`'s", mbedtls_pk_type_name(type), size, - host, mbedtls_pk_get_name(&certs.p[i].cert->pk), + DEBUGF("(ssl) TlsRoute(%s, %`'.*s) %s %`'s", mbedtls_pk_type_name(type), + size, host, mbedtls_pk_get_name(&certs.p[i].cert->pk), gc(FormatX509Name(&certs.p[i].cert->subject))); return true; } @@ -1807,8 +1810,8 @@ static void IndexAssets(void) { if (!IsCompressionMethodSupported( ZIP_CFILE_COMPRESSIONMETHOD(zbase + cf))) { WARNF("(zip) don't understand zip compression method %d used by %`'.*s", - ZIP_CFILE_COMPRESSIONMETHOD(zbase + cf), - ZIP_CFILE_NAMESIZE(zbase + cf), ZIP_CFILE_NAME(zbase + cf)); + ZIP_CFILE_COMPRESSIONMETHOD(zbase + cf), + ZIP_CFILE_NAMESIZE(zbase + cf), ZIP_CFILE_NAME(zbase + cf)); continue; } hash = Hash(ZIP_CFILE_NAME(zbase + cf), ZIP_CFILE_NAMESIZE(zbase + cf)); @@ -2290,10 +2293,11 @@ static char *ServeError(unsigned code, const char *reason) { } static char *ServeFailure(unsigned code, const char *reason) { - ERRORF("(srvr) failure: %d %s %s HTTP%02d %.*s %`'.*s %`'.*s %`'.*s %`'.*s", code, - reason, DescribeClient(), msg.version, msg.xmethod.b - msg.xmethod.a, - inbuf.p + msg.xmethod.a, HeaderLength(kHttpHost), HeaderData(kHttpHost), - msg.uri.b - msg.uri.a, inbuf.p + msg.uri.a, HeaderLength(kHttpReferer), + ERRORF("(srvr) failure: %d %s %s HTTP%02d %.*s %`'.*s %`'.*s %`'.*s %`'.*s", + code, reason, DescribeClient(), msg.version, + msg.xmethod.b - msg.xmethod.a, inbuf.p + msg.xmethod.a, + HeaderLength(kHttpHost), HeaderData(kHttpHost), msg.uri.b - msg.uri.a, + inbuf.p + msg.uri.a, HeaderLength(kHttpReferer), HeaderData(kHttpReferer), HeaderLength(kHttpUserAgent), HeaderData(kHttpUserAgent)); return ServeErrorImpl(code, reason, NULL); @@ -2325,11 +2329,11 @@ static ssize_t DeflateGenerator(struct iovec v[3]) { no = dg.s.avail_in; rc = deflate(&dg.s, dg.i < contentlength ? Z_SYNC_FLUSH : Z_FINISH); if (rc != Z_OK && rc != Z_STREAM_END) { - DIEF("(zip) deflate()→%d oldin:%,zu/%,zu in:%,zu/%,zu out:%,zu/%,zu", rc, no, - dg.z, dg.s.avail_in, dg.z, dg.s.avail_out, dg.z); + DIEF("(zip) deflate()→%d oldin:%,zu/%,zu in:%,zu/%,zu out:%,zu/%,zu", rc, + no, dg.z, dg.s.avail_in, dg.z, dg.s.avail_out, dg.z); } else { - NOISEF("(zip) deflate()→%d oldin:%,zu/%,zu in:%,zu/%,zu out:%,zu/%,zu", rc, no, - dg.z, dg.s.avail_in, dg.z, dg.s.avail_out, dg.z); + NOISEF("(zip) deflate()→%d oldin:%,zu/%,zu in:%,zu/%,zu out:%,zu/%,zu", rc, + no, dg.z, dg.s.avail_in, dg.z, dg.s.avail_out, dg.z); } no = dg.z - dg.s.avail_out; if (no) { @@ -2488,7 +2492,8 @@ static char *ServeAssetRange(struct Asset *a) { return p; } else { LockInc(&shared->c.badranges); - WARNF("(client) bad range %`'.*s", HeaderLength(kHttpRange), HeaderData(kHttpRange)); + WARNF("(client) bad range %`'.*s", HeaderLength(kHttpRange), + HeaderData(kHttpRange)); p = SetStatus(416, "Range Not Satisfiable"); p = AppendContentRange(p, -1, -1, contentlength); content = ""; @@ -3817,8 +3822,9 @@ static int LuaFetch(lua_State *L) { Finished: if (paylen && logbodies) LogBody("received", inbuf.p + hdrsize, paylen); - VERBOSEF("(ftch) completed %s HTTP%02d %d %s %`'.*s", method, msg.version, msg.status, - urlarg, HeaderLength(kHttpServer), HeaderData(kHttpServer)); + VERBOSEF("(ftch) completed %s HTTP%02d %d %s %`'.*s", method, msg.version, + msg.status, urlarg, HeaderLength(kHttpServer), + HeaderData(kHttpServer)); if (followredirect && HasHeader(kHttpLocation) && (msg.status == 301 || msg.status == 308 || // permanent redirects msg.status == 302 || msg.status == 307 || // temporary redirects @@ -4185,10 +4191,11 @@ static int LuaSetCookie(lua_State *L) { unreachable; } - ishostpref = keylen > strlen(hostpref) - && SlicesEqual(key, strlen(hostpref), hostpref, strlen(hostpref)); - issecurepref = keylen > strlen(securepref) - && SlicesEqual(key, strlen(securepref), securepref, strlen(securepref)); + ishostpref = keylen > strlen(hostpref) && + SlicesEqual(key, strlen(hostpref), hostpref, strlen(hostpref)); + issecurepref = + keylen > strlen(securepref) && + SlicesEqual(key, strlen(securepref), securepref, strlen(securepref)); if ((ishostpref || issecurepref) && !usessl) { luaL_argerror(L, 1, "__Host- and __Secure- prefixes require SSL"); unreachable; @@ -4199,11 +4206,11 @@ static int LuaSetCookie(lua_State *L) { appends(&buf, val); if (lua_istable(L, 3)) { - if (lua_getfield(L, 3, "expires") != LUA_TNIL - || lua_getfield(L, 3, "Expires") != LUA_TNIL) { + if (lua_getfield(L, 3, "expires") != LUA_TNIL || + lua_getfield(L, 3, "Expires") != LUA_TNIL) { if (lua_isnumber(L, -1)) { - expires = FormatUnixHttpDateTime( - FreeLater(xmalloc(30)), lua_tonumber(L, -1)); + expires = + FormatUnixHttpDateTime(FreeLater(xmalloc(30)), lua_tonumber(L, -1)); } else { expires = lua_tostring(L, -1); if (!ParseHttpDateTime(expires, -1)) { @@ -4215,46 +4222,44 @@ static int LuaSetCookie(lua_State *L) { appends(&buf, expires); } - if ((lua_getfield(L, 3, "maxage") == LUA_TNUMBER - || lua_getfield(L, 3, "MaxAge") == LUA_TNUMBER) - && lua_isinteger(L, -1)) { + if ((lua_getfield(L, 3, "maxage") == LUA_TNUMBER || + lua_getfield(L, 3, "MaxAge") == LUA_TNUMBER) && + lua_isinteger(L, -1)) { appends(&buf, "; Max-Age="); appends(&buf, lua_tostring(L, -1)); } - if (lua_getfield(L, 3, "samesite") == LUA_TSTRING - || lua_getfield(L, 3, "SameSite") == LUA_TSTRING) { - samesite = lua_tostring(L, -1); // also used in the Secure check + if (lua_getfield(L, 3, "samesite") == LUA_TSTRING || + lua_getfield(L, 3, "SameSite") == LUA_TSTRING) { + samesite = lua_tostring(L, -1); // also used in the Secure check appends(&buf, "; SameSite="); appends(&buf, samesite); } // Secure attribute is required for __Host and __Secure prefixes // as well as for the SameSite=None - if (ishostpref || issecurepref || !strcmp(samesite, "None") - || ((lua_getfield(L, 3, "secure") == LUA_TBOOLEAN - || lua_getfield(L, 3, "Secure") == LUA_TBOOLEAN) - && lua_toboolean(L, -1))) { + if (ishostpref || issecurepref || !strcmp(samesite, "None") || + ((lua_getfield(L, 3, "secure") == LUA_TBOOLEAN || + lua_getfield(L, 3, "Secure") == LUA_TBOOLEAN) && + lua_toboolean(L, -1))) { appends(&buf, "; Secure"); } - if (!ishostpref - && (lua_getfield(L, 3, "domain") == LUA_TSTRING - || lua_getfield(L, 3, "Domain") == LUA_TSTRING)) { + if (!ishostpref && (lua_getfield(L, 3, "domain") == LUA_TSTRING || + lua_getfield(L, 3, "Domain") == LUA_TSTRING)) { appends(&buf, "; Domain="); appends(&buf, lua_tostring(L, -1)); } - if (ishostpref - || lua_getfield(L, 3, "path") == LUA_TSTRING - || lua_getfield(L, 3, "Path") == LUA_TSTRING) { + if (ishostpref || lua_getfield(L, 3, "path") == LUA_TSTRING || + lua_getfield(L, 3, "Path") == LUA_TSTRING) { appends(&buf, "; Path="); appends(&buf, ishostpref ? "/" : lua_tostring(L, -1)); } - if ((lua_getfield(L, 3, "httponly") == LUA_TBOOLEAN - || lua_getfield(L, 3, "HttpOnly") == LUA_TBOOLEAN) - && lua_toboolean(L, -1)) { + if ((lua_getfield(L, 3, "httponly") == LUA_TBOOLEAN || + lua_getfield(L, 3, "HttpOnly") == LUA_TBOOLEAN) && + lua_toboolean(L, -1)) { appends(&buf, "; HttpOnly"); } } @@ -6234,8 +6239,8 @@ static bool HandleMessageAcutal(void) { LockInc(&shared->c.messageshandled); ++messageshandled; if (loglatency || LOGGABLE(kLogDebug)) { - LOGF(kLogDebug, "(stat) %`'.*s latency %,ldµs", msg.uri.b - msg.uri.a, inbuf.p + msg.uri.a, - (long)((nowl() - startrequest) * 1e6L)); + LOGF(kLogDebug, "(stat) %`'.*s latency %,ldµs", msg.uri.b - msg.uri.a, + inbuf.p + msg.uri.a, (long)((nowl() - startrequest) * 1e6L)); } if (!generator) { return TransmitResponse(p); @@ -6491,7 +6496,8 @@ static void HandleConnection(size_t i) { } else if (errno == ENETUNREACH || errno == EHOSTUNREACH || errno == EOPNOTSUPP || errno == ENOPROTOOPT || errno == EPROTO) { LockInc(&shared->c.accepterrors); - WARNF("(srvr) %s ephemeral accept error %s", DescribeServer(), strerror(errno)); + WARNF("(srvr) %s ephemeral accept error %s", DescribeServer(), + strerror(errno)); } else { DIEF("(srvr) %s accept error %s", DescribeServer(), strerror(errno)); } @@ -6585,8 +6591,8 @@ static void Listen(void) { port = ntohs(servers.p[n].addr.sin_port); ip = ntohl(servers.p[n].addr.sin_addr.s_addr); if (ip == INADDR_ANY) ip = INADDR_LOOPBACK; - INFOF("(srvr) listen http://%hhu.%hhu.%hhu.%hhu:%d", ip >> 24, ip >> 16, ip >> 8, - ip, port); + INFOF("(srvr) listen http://%hhu.%hhu.%hhu.%hhu:%d", ip >> 24, ip >> 16, + ip >> 8, ip, port); if (printport && !ports.p[j]) { printf("%d\n", port); fflush(stdout);