deprecate cuchar, don't redefine it (#18505)

This commit is contained in:
Andreas Rumpf 2021-07-16 15:50:02 +02:00 • committed by GitHub
commit 96a7f9b31c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 55 additions and 54 deletions

View file

@ -6,7 +6,8 @@
- Deprecated `std/mersenne` - Deprecated `std/mersenne`
- `cuchar` now aliases `uint8` instead of `char` - `cuchar` is now deprecated as it aliased `char` where arguably it should have aliased `uint8`.
Please use `char` or `uint8` instead.
- `repr` now doesn't insert trailing newline; previous behavior was very inconsistent, - `repr` now doesn't insert trailing newline; previous behavior was very inconsistent,
see #16034. Use `-d:nimLegacyReprWithNewline` for previous behavior. see #16034. Use `-d:nimLegacyReprWithNewline` for previous behavior.

View file

@ -47,7 +47,7 @@ type
d_ino*: Ino d_ino*: Ino
d_off*: Off d_off*: Off
d_reclen*: cushort d_reclen*: cushort
d_type*: int8 # cuchar really! d_type*: int8 # uint8 really!
d_name*: array[256, cchar] d_name*: array[256, cchar]
Tflock* {.importc: "struct flock", final, pure, Tflock* {.importc: "struct flock", final, pure,

View file

@ -33,7 +33,7 @@ type
Dirent* {.importc: "struct dirent", Dirent* {.importc: "struct dirent",
header: "<dirent.h>", final, pure.} = object ## dirent_t struct header: "<dirent.h>", final, pure.} = object ## dirent_t struct
d_ino*: Ino d_ino*: Ino
d_type*: int8 # cuchar really! d_type*: int8 # uint8 really!
d_name*: array[256, cchar] d_name*: array[256, cchar]
Tflock* {.importc: "struct flock", final, pure, Tflock* {.importc: "struct flock", final, pure,
@ -347,20 +347,20 @@ type
SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>", SockAddr* {.importc: "struct sockaddr", header: "<sys/socket.h>",
pure, final.} = object ## struct sockaddr pure, final.} = object ## struct sockaddr
sa_len: cuchar sa_len: uint8
sa_family*: TSa_Family ## Address family. sa_family*: TSa_Family ## Address family.
sa_data*: array[14, char] ## Socket address (variable-length data). sa_data*: array[14, char] ## Socket address (variable-length data).
Sockaddr_storage* {.importc: "struct sockaddr_storage", Sockaddr_storage* {.importc: "struct sockaddr_storage",
header: "<sys/socket.h>", header: "<sys/socket.h>",
pure, final.} = object ## struct sockaddr_storage pure, final.} = object ## struct sockaddr_storage
ss_len: cuchar ss_len: uint8
ss_family*: TSa_Family ## Address family. ss_family*: TSa_Family ## Address family.
ss_padding1: array[64 - sizeof(cuchar) - sizeof(cshort), char] ss_padding1: array[64 - sizeof(uint8) - sizeof(cshort), char]
ss_align: clonglong ss_align: clonglong
ss_padding2: array[ ss_padding2: array[
128 - sizeof(cuchar) - sizeof(cshort) - 128 - sizeof(uint8) - sizeof(cshort) -
(64 - sizeof(cuchar) - sizeof(cshort)) - 64, char] (64 - sizeof(uint8) - sizeof(cshort)) - 64, char]
Tif_nameindex* {.importc: "struct if_nameindex", final, Tif_nameindex* {.importc: "struct if_nameindex", final,
pure, header: "<net/if.h>".} = object ## struct if_nameindex pure, header: "<net/if.h>".} = object ## struct if_nameindex

View file

@ -450,15 +450,15 @@ when useGCC_builtins:
elif useVCC_builtins: elif useVCC_builtins:
# Search the mask data from most significant bit (MSB) to least significant bit (LSB) for a set bit (1). # Search the mask data from most significant bit (MSB) to least significant bit (LSB) for a set bit (1).
func bitScanReverse(index: ptr culong, mask: culong): cuchar {. func bitScanReverse(index: ptr culong, mask: culong): uint8 {.
importc: "_BitScanReverse", header: "<intrin.h>".} importc: "_BitScanReverse", header: "<intrin.h>".}
func bitScanReverse64(index: ptr culong, mask: uint64): cuchar {. func bitScanReverse64(index: ptr culong, mask: uint64): uint8 {.
importc: "_BitScanReverse64", header: "<intrin.h>".} importc: "_BitScanReverse64", header: "<intrin.h>".}
# Search the mask data from least significant bit (LSB) to the most significant bit (MSB) for a set bit (1). # Search the mask data from least significant bit (LSB) to the most significant bit (MSB) for a set bit (1).
func bitScanForward(index: ptr culong, mask: culong): cuchar {. func bitScanForward(index: ptr culong, mask: culong): uint8 {.
importc: "_BitScanForward", header: "<intrin.h>".} importc: "_BitScanForward", header: "<intrin.h>".}
func bitScanForward64(index: ptr culong, mask: uint64): cuchar {. func bitScanForward64(index: ptr culong, mask: uint64): uint8 {.
importc: "_BitScanForward64", header: "<intrin.h>".} importc: "_BitScanForward64", header: "<intrin.h>".}
template vcc_scan_impl(fnc: untyped; v: untyped): int = template vcc_scan_impl(fnc: untyped; v: untyped): int =
@ -468,15 +468,15 @@ elif useVCC_builtins:
elif useICC_builtins: elif useICC_builtins:
# Returns the number of trailing 0-bits in x, starting at the least significant bit position. If x is 0, the result is undefined. # Returns the number of trailing 0-bits in x, starting at the least significant bit position. If x is 0, the result is undefined.
func bitScanForward(p: ptr uint32, b: uint32): cuchar {. func bitScanForward(p: ptr uint32, b: uint32): uint8 {.
importc: "_BitScanForward", header: "<immintrin.h>".} importc: "_BitScanForward", header: "<immintrin.h>".}
func bitScanForward64(p: ptr uint32, b: uint64): cuchar {. func bitScanForward64(p: ptr uint32, b: uint64): uint8 {.
importc: "_BitScanForward64", header: "<immintrin.h>".} importc: "_BitScanForward64", header: "<immintrin.h>".}
# Returns the number of leading 0-bits in x, starting at the most significant bit position. If x is 0, the result is undefined. # Returns the number of leading 0-bits in x, starting at the most significant bit position. If x is 0, the result is undefined.
func bitScanReverse(p: ptr uint32, b: uint32): cuchar {. func bitScanReverse(p: ptr uint32, b: uint32): uint8 {.
importc: "_BitScanReverse", header: "<immintrin.h>".} importc: "_BitScanReverse", header: "<immintrin.h>".}
func bitScanReverse64(p: ptr uint32, b: uint64): cuchar {. func bitScanReverse64(p: ptr uint32, b: uint64): uint8 {.
importc: "_BitScanReverse64", header: "<immintrin.h>".} importc: "_BitScanReverse64", header: "<immintrin.h>".}
template icc_scan_impl(fnc: untyped; v: untyped): int = template icc_scan_impl(fnc: untyped; v: untyped): int =
@ -664,7 +664,7 @@ when useBuiltinsRotate:
when defined(gcc): when defined(gcc):
# GCC was tested until version 4.8.1 and intrinsics were present. Not tested # GCC was tested until version 4.8.1 and intrinsics were present. Not tested
# in previous versions. # in previous versions.
func builtin_rotl8(value: cuchar, shift: cint): cuchar func builtin_rotl8(value: uint8, shift: cint): uint8
{.importc: "__rolb", header: "<x86intrin.h>".} {.importc: "__rolb", header: "<x86intrin.h>".}
func builtin_rotl16(value: cushort, shift: cint): cushort func builtin_rotl16(value: cushort, shift: cint): cushort
{.importc: "__rolw", header: "<x86intrin.h>".} {.importc: "__rolw", header: "<x86intrin.h>".}
@ -674,7 +674,7 @@ when useBuiltinsRotate:
func builtin_rotl64(value: culonglong, shift: cint): culonglong func builtin_rotl64(value: culonglong, shift: cint): culonglong
{.importc: "__rolq", header: "<x86intrin.h>".} {.importc: "__rolq", header: "<x86intrin.h>".}
func builtin_rotr8(value: cuchar, shift: cint): cuchar func builtin_rotr8(value: uint8, shift: cint): uint8
{.importc: "__rorb", header: "<x86intrin.h>".} {.importc: "__rorb", header: "<x86intrin.h>".}
func builtin_rotr16(value: cushort, shift: cint): cushort func builtin_rotr16(value: cushort, shift: cint): cushort
{.importc: "__rorw", header: "<x86intrin.h>".} {.importc: "__rorw", header: "<x86intrin.h>".}
@ -690,7 +690,7 @@ when useBuiltinsRotate:
# https://releases.llvm.org/8.0.0/tools/clang/docs/ReleaseNotes.html#non-comprehensive-list-of-changes-in-this-release # https://releases.llvm.org/8.0.0/tools/clang/docs/ReleaseNotes.html#non-comprehensive-list-of-changes-in-this-release
# https://releases.llvm.org/8.0.0/tools/clang/docs/LanguageExtensions.html#builtin-rotateleft # https://releases.llvm.org/8.0.0/tools/clang/docs/LanguageExtensions.html#builtin-rotateleft
# source for correct declarations: https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/Builtins.def # source for correct declarations: https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Basic/Builtins.def
func builtin_rotl8(value: cuchar, shift: cuchar): cuchar func builtin_rotl8(value: uint8, shift: uint8): uint8
{.importc: "__builtin_rotateleft8", nodecl.} {.importc: "__builtin_rotateleft8", nodecl.}
func builtin_rotl16(value: cushort, shift: cushort): cushort func builtin_rotl16(value: cushort, shift: cushort): cushort
{.importc: "__builtin_rotateleft16", nodecl.} {.importc: "__builtin_rotateleft16", nodecl.}
@ -700,7 +700,7 @@ when useBuiltinsRotate:
func builtin_rotl64(value: culonglong, shift: culonglong): culonglong func builtin_rotl64(value: culonglong, shift: culonglong): culonglong
{.importc: "__builtin_rotateleft64", nodecl.} {.importc: "__builtin_rotateleft64", nodecl.}
func builtin_rotr8(value: cuchar, shift: cuchar): cuchar func builtin_rotr8(value: uint8, shift: uint8): uint8
{.importc: "__builtin_rotateright8", nodecl.} {.importc: "__builtin_rotateright8", nodecl.}
func builtin_rotr16(value: cushort, shift: cushort): cushort func builtin_rotr16(value: cushort, shift: cushort): cushort
{.importc: "__builtin_rotateright16", nodecl.} {.importc: "__builtin_rotateright16", nodecl.}
@ -716,9 +716,9 @@ when useBuiltinsRotate:
# https://docs.microsoft.com/en-us/cpp/intrinsics/rotl8-rotl16?view=msvc-160 # https://docs.microsoft.com/en-us/cpp/intrinsics/rotl8-rotl16?view=msvc-160
# https://docs.microsoft.com/en-us/cpp/intrinsics/rotr8-rotr16?view=msvc-160 # https://docs.microsoft.com/en-us/cpp/intrinsics/rotr8-rotr16?view=msvc-160
# https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/rotl-rotl64-rotr-rotr64?view=msvc-160 # https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/rotl-rotl64-rotr-rotr64?view=msvc-160
func builtin_rotl8(value: cuchar, shift: cuchar): cuchar func builtin_rotl8(value: uint8, shift: uint8): uint8
{.importc: "_rotl8", header: "<intrin.h>".} {.importc: "_rotl8", header: "<intrin.h>".}
func builtin_rotl16(value: cushort, shift: cuchar): cushort func builtin_rotl16(value: cushort, shift: uint8): cushort
{.importc: "_rotl16", header: "<intrin.h>".} {.importc: "_rotl16", header: "<intrin.h>".}
func builtin_rotl32(value: cuint, shift: cint): cuint func builtin_rotl32(value: cuint, shift: cint): cuint
{.importc: "_rotl", header: "<stdlib.h>".} {.importc: "_rotl", header: "<stdlib.h>".}
@ -726,9 +726,9 @@ when useBuiltinsRotate:
func builtin_rotl64(value: culonglong, shift: cint): culonglong func builtin_rotl64(value: culonglong, shift: cint): culonglong
{.importc: "_rotl64", header: "<stdlib.h>".} {.importc: "_rotl64", header: "<stdlib.h>".}
func builtin_rotr8(value: cuchar, shift: cuchar): cuchar func builtin_rotr8(value: uint8, shift: uint8): uint8
{.importc: "_rotr8", header: "<intrin.h>".} {.importc: "_rotr8", header: "<intrin.h>".}
func builtin_rotr16(value: cushort, shift: cuchar): cushort func builtin_rotr16(value: cushort, shift: uint8): cushort
{.importc: "_rotr16", header: "<intrin.h>".} {.importc: "_rotr16", header: "<intrin.h>".}
func builtin_rotr32(value: cuint, shift: cint): cuint func builtin_rotr32(value: cuint, shift: cint): cuint
{.importc: "_rotr", header: "<stdlib.h>".} {.importc: "_rotr", header: "<stdlib.h>".}
@ -738,7 +738,7 @@ when useBuiltinsRotate:
elif defined(icl): elif defined(icl):
# Tested on Intel(R) C++ Intel(R) 64 Compiler Classic Version 2021.1.2 Build # Tested on Intel(R) C++ Intel(R) 64 Compiler Classic Version 2021.1.2 Build
# 20201208_000000 x64 and x86. Not tested in previous versions. # 20201208_000000 x64 and x86. Not tested in previous versions.
func builtin_rotl8(value: cuchar, shift: cint): cuchar func builtin_rotl8(value: uint8, shift: cint): uint8
{.importc: "__rolb", header: "<immintrin.h>".} {.importc: "__rolb", header: "<immintrin.h>".}
func builtin_rotl16(value: cushort, shift: cint): cushort func builtin_rotl16(value: cushort, shift: cint): cushort
{.importc: "__rolw", header: "<immintrin.h>".} {.importc: "__rolw", header: "<immintrin.h>".}
@ -748,7 +748,7 @@ when useBuiltinsRotate:
func builtin_rotl64(value: culonglong, shift: cint): culonglong func builtin_rotl64(value: culonglong, shift: cint): culonglong
{.importc: "__rolq", header: "<immintrin.h>".} {.importc: "__rolq", header: "<immintrin.h>".}
func builtin_rotr8(value: cuchar, shift: cint): cuchar func builtin_rotr8(value: uint8, shift: cint): uint8
{.importc: "__rorb", header: "<immintrin.h>".} {.importc: "__rorb", header: "<immintrin.h>".}
func builtin_rotr16(value: cushort, shift: cint): cushort func builtin_rotr16(value: cushort, shift: cint): cushort
{.importc: "__rorw", header: "<immintrin.h>".} {.importc: "__rorw", header: "<immintrin.h>".}
@ -777,7 +777,7 @@ func shiftTypeTo(size: static int, shift: int): auto {.inline.} =
when (defined(vcc) and (size in [4, 8])) or defined(gcc) or defined(icl): when (defined(vcc) and (size in [4, 8])) or defined(gcc) or defined(icl):
cint(shift) cint(shift)
elif (defined(vcc) and (size in [1, 2])) or (defined(clang) and size == 1): elif (defined(vcc) and (size in [1, 2])) or (defined(clang) and size == 1):
cuchar(shift) uint8(shift)
elif defined(clang): elif defined(clang):
when size == 2: when size == 2:
cushort(shift) cushort(shift)
@ -802,7 +802,7 @@ func rotateLeftBits*[T: SomeUnsignedInt](value: T, shift: range[0..(sizeof(T) *
when useBuiltinsRotate: when useBuiltinsRotate:
const size = sizeof(T) const size = sizeof(T)
when size == 1: when size == 1:
builtin_rotl8(value.cuchar, shiftTypeTo(size, shift)).T builtin_rotl8(value.uint8, shiftTypeTo(size, shift)).T
elif size == 2: elif size == 2:
builtin_rotl16(value.cushort, shiftTypeTo(size, shift)).T builtin_rotl16(value.cushort, shiftTypeTo(size, shift)).T
elif size == 4: elif size == 4:
@ -830,7 +830,7 @@ func rotateRightBits*[T: SomeUnsignedInt](value: T, shift: range[0..(sizeof(T) *
when useBuiltinsRotate: when useBuiltinsRotate:
const size = sizeof(T) const size = sizeof(T)
when size == 1: when size == 1:
builtin_rotr8(value.cuchar, shiftTypeTo(size, shift)).T builtin_rotr8(value.uint8, shiftTypeTo(size, shift)).T
elif size == 2: elif size == 2:
builtin_rotr16(value.cushort, shiftTypeTo(size, shift)).T builtin_rotr16(value.cushort, shiftTypeTo(size, shift)).T
elif size == 4: elif size == 4:

View file

@ -688,7 +688,7 @@ when defineSsl:
return ctx.getExtraInternal().clientGetPskFunc return ctx.getExtraInternal().clientGetPskFunc
proc pskClientCallback(ssl: SslPtr; hint: cstring; identity: cstring; proc pskClientCallback(ssl: SslPtr; hint: cstring; identity: cstring;
max_identity_len: cuint; psk: ptr cuchar; max_identity_len: cuint; psk: ptr uint8;
max_psk_len: cuint): cuint {.cdecl.} = max_psk_len: cuint): cuint {.cdecl.} =
let ctx = SslContext(context: ssl.SSL_get_SSL_CTX) let ctx = SslContext(context: ssl.SSL_get_SSL_CTX)
let hintString = if hint == nil: "" else: $hint let hintString = if hint == nil: "" else: $hint
@ -714,7 +714,7 @@ when defineSsl:
proc serverGetPskFunc*(ctx: SslContext): SslServerGetPskFunc = proc serverGetPskFunc*(ctx: SslContext): SslServerGetPskFunc =
return ctx.getExtraInternal().serverGetPskFunc return ctx.getExtraInternal().serverGetPskFunc
proc pskServerCallback(ssl: SslCtx; identity: cstring; psk: ptr cuchar; proc pskServerCallback(ssl: SslCtx; identity: cstring; psk: ptr uint8;
max_psk_len: cint): cuint {.cdecl.} = max_psk_len: cint): cuint {.cdecl.} =
let ctx = SslContext(context: ssl.SSL_get_SSL_CTX) let ctx = SslContext(context: ssl.SSL_get_SSL_CTX)
let pskString = (ctx.serverGetPskFunc)($identity) let pskString = (ctx.serverGetPskFunc)($identity)

View file

@ -132,7 +132,7 @@ elif defined(windows):
type type
PVOID = pointer PVOID = pointer
BCRYPT_ALG_HANDLE = PVOID BCRYPT_ALG_HANDLE = PVOID
PUCHAR = ptr cuchar PUCHAR = ptr uint8
NTSTATUS = clong NTSTATUS = clong
ULONG = culong ULONG = culong

View file

@ -1427,8 +1427,8 @@ type # these work for most platforms:
## This is the same as the type `long double` in *C*. ## This is the same as the type `long double` in *C*.
## This C type is not supported by Nim's code generator. ## This C type is not supported by Nim's code generator.
cuchar* {.importc: "unsigned char", nodecl.} = uint8 cuchar* {.importc: "unsigned char", nodecl, deprecated: "use `char` or `uint8` instead".} = char
## This is the same as the type `unsigned char` in *C*. ## Deprecated: Use `uint8` instead.
cushort* {.importc: "unsigned short", nodecl.} = uint16 cushort* {.importc: "unsigned short", nodecl.} = uint16
## This is the same as the type `unsigned short` in *C*. ## This is the same as the type `unsigned short` in *C*.
cuint* {.importc: "unsigned int", nodecl.} = uint32 cuint* {.importc: "unsigned int", nodecl.} = uint32

View file

@ -42,7 +42,7 @@ type
PULONG_PTR* = ptr uint PULONG_PTR* = ptr uint
HDC* = Handle HDC* = Handle
HGLRC* = Handle HGLRC* = Handle
BYTE* = cuchar BYTE* = uint8
SECURITY_ATTRIBUTES* {.final, pure.} = object SECURITY_ATTRIBUTES* {.final, pure.} = object
nLength*: int32 nLength*: int32

View file

@ -520,16 +520,16 @@ proc OPENSSL_sk_num*(stack: PSTACK): int {.cdecl, dynlib: DLLSSLName, importc.}
proc OPENSSL_sk_value*(stack: PSTACK, index: int): pointer {.cdecl, proc OPENSSL_sk_value*(stack: PSTACK, index: int): pointer {.cdecl,
dynlib: DLLSSLName, importc.} dynlib: DLLSSLName, importc.}
proc d2i_X509*(px: ptr PX509, i: ptr ptr cuchar, len: cint): PX509 {.cdecl, proc d2i_X509*(px: ptr PX509, i: ptr ptr uint8, len: cint): PX509 {.cdecl,
dynlib: DLLUtilName, importc.} dynlib: DLLUtilName, importc.}
proc i2d_X509*(cert: PX509; o: ptr ptr cuchar): cint {.cdecl, proc i2d_X509*(cert: PX509; o: ptr ptr uint8): cint {.cdecl,
dynlib: DLLUtilName, importc.} dynlib: DLLUtilName, importc.}
proc d2i_X509*(b: string): PX509 = proc d2i_X509*(b: string): PX509 =
## decode DER/BER bytestring into X.509 certificate struct ## decode DER/BER bytestring into X.509 certificate struct
var bb = b.cstring var bb = b.cstring
let i = cast[ptr ptr cuchar](addr bb) let i = cast[ptr ptr uint8](addr bb)
let ret = d2i_X509(addr result, i, b.len.cint) let ret = d2i_X509(addr result, i, b.len.cint)
if ret.isNil: if ret.isNil:
raise newException(Exception, "X.509 certificate decoding failed") raise newException(Exception, "X.509 certificate decoding failed")
@ -539,7 +539,7 @@ proc i2d_X509*(cert: PX509): string =
let encoded_length = i2d_X509(cert, nil) let encoded_length = i2d_X509(cert, nil)
result = newString(encoded_length) result = newString(encoded_length)
var q = result.cstring var q = result.cstring
let o = cast[ptr ptr cuchar](addr q) let o = cast[ptr ptr uint8](addr q)
let length = i2d_X509(cert, o) let length = i2d_X509(cert, o)
if length.int <= 0: if length.int <= 0:
raise newException(Exception, "X.509 certificate encoding failed") raise newException(Exception, "X.509 certificate encoding failed")
@ -599,11 +599,11 @@ proc SSL_CTX_set_tlsext_servername_arg*(ctx: SslCtx, arg: pointer): int =
type type
PskClientCallback* = proc (ssl: SslPtr; PskClientCallback* = proc (ssl: SslPtr;
hint: cstring; identity: cstring; max_identity_len: cuint; psk: ptr cuchar; hint: cstring; identity: cstring; max_identity_len: cuint; psk: ptr uint8;
max_psk_len: cuint): cuint {.cdecl.} max_psk_len: cuint): cuint {.cdecl.}
PskServerCallback* = proc (ssl: SslPtr; PskServerCallback* = proc (ssl: SslPtr;
identity: cstring; psk: ptr cuchar; max_psk_len: cint): cuint {.cdecl.} identity: cstring; psk: ptr uint8; max_psk_len: cint): cuint {.cdecl.}
proc SSL_CTX_set_psk_client_callback*(ctx: SslCtx; callback: PskClientCallback) {.cdecl, dynlib: DLLSSLName, importc.} proc SSL_CTX_set_psk_client_callback*(ctx: SslCtx; callback: PskClientCallback) {.cdecl, dynlib: DLLSSLName, importc.}
## Set callback called when OpenSSL needs PSK (for client). ## Set callback called when OpenSSL needs PSK (for client).
@ -672,13 +672,13 @@ proc PEM_read_bio_RSAPublicKey*(bp: BIO, x: ptr PRSA, cb: pem_password_cb, u: po
dynlib: DLLUtilName, importc.} dynlib: DLLUtilName, importc.}
proc PEM_read_bio_RSAPrivateKey*(bp: BIO, x: ptr PRSA, cb: pem_password_cb, u: pointer): PRSA {.cdecl, proc PEM_read_bio_RSAPrivateKey*(bp: BIO, x: ptr PRSA, cb: pem_password_cb, u: pointer): PRSA {.cdecl,
dynlib: DLLUtilName, importc.} dynlib: DLLUtilName, importc.}
proc RSA_private_encrypt*(flen: cint, fr: ptr cuchar, to: ptr cuchar, rsa: PRSA, padding: PaddingType): cint {.cdecl, proc RSA_private_encrypt*(flen: cint, fr: ptr uint8, to: ptr uint8, rsa: PRSA, padding: PaddingType): cint {.cdecl,
dynlib: DLLUtilName, importc.} dynlib: DLLUtilName, importc.}
proc RSA_public_encrypt*(flen: cint, fr: ptr cuchar, to: ptr cuchar, rsa: PRSA, padding: PaddingType): cint {.cdecl, proc RSA_public_encrypt*(flen: cint, fr: ptr uint8, to: ptr uint8, rsa: PRSA, padding: PaddingType): cint {.cdecl,
dynlib: DLLUtilName, importc.} dynlib: DLLUtilName, importc.}
proc RSA_private_decrypt*(flen: cint, fr: ptr cuchar, to: ptr cuchar, rsa: PRSA, padding: PaddingType): cint {.cdecl, proc RSA_private_decrypt*(flen: cint, fr: ptr uint8, to: ptr uint8, rsa: PRSA, padding: PaddingType): cint {.cdecl,
dynlib: DLLUtilName, importc.} dynlib: DLLUtilName, importc.}
proc RSA_public_decrypt*(flen: cint, fr: ptr cuchar, to: ptr cuchar, rsa: PRSA, padding: PaddingType): cint {.cdecl, proc RSA_public_decrypt*(flen: cint, fr: ptr uint8, to: ptr uint8, rsa: PRSA, padding: PaddingType): cint {.cdecl,
dynlib: DLLUtilName, importc.} dynlib: DLLUtilName, importc.}
proc RSA_free*(rsa: PRSA) {.cdecl, dynlib: DLLUtilName, importc.} proc RSA_free*(rsa: PRSA) {.cdecl, dynlib: DLLUtilName, importc.}
proc RSA_size*(rsa: PRSA): cint {.cdecl, dynlib: DLLUtilName, importc.} proc RSA_size*(rsa: PRSA): cint {.cdecl, dynlib: DLLUtilName, importc.}
@ -744,8 +744,8 @@ type
proc md5_Init*(c: var MD5_CTX): cint{.importc: "MD5_Init".} proc md5_Init*(c: var MD5_CTX): cint{.importc: "MD5_Init".}
proc md5_Update*(c: var MD5_CTX; data: pointer; len: csize_t): cint{.importc: "MD5_Update".} proc md5_Update*(c: var MD5_CTX; data: pointer; len: csize_t): cint{.importc: "MD5_Update".}
proc md5_Final*(md: cstring; c: var MD5_CTX): cint{.importc: "MD5_Final".} proc md5_Final*(md: cstring; c: var MD5_CTX): cint{.importc: "MD5_Final".}
proc md5*(d: ptr cuchar; n: csize_t; md: ptr cuchar): ptr cuchar{.importc: "MD5".} proc md5*(d: ptr uint8; n: csize_t; md: ptr uint8): ptr uint8{.importc: "MD5".}
proc md5_Transform*(c: var MD5_CTX; b: ptr cuchar){.importc: "MD5_Transform".} proc md5_Transform*(c: var MD5_CTX; b: ptr uint8){.importc: "MD5_Transform".}
{.pop.} {.pop.}
from strutils import toHex, toLowerAscii from strutils import toHex, toLowerAscii

View file

@ -12,8 +12,8 @@ proc rsaPublicEncrypt(fr: string): string =
doAssert rsa != nil doAssert rsa != nil
doAssert BIO_free(bio) >= 0 doAssert BIO_free(bio) >= 0
result = newString(RSA_size(rsa)) result = newString(RSA_size(rsa))
let frdata = cast[ptr cuchar](fr.cstring) let frdata = cast[ptr uint8](fr.cstring)
var todata = cast[ptr cuchar](result.cstring) var todata = cast[ptr uint8](result.cstring)
doAssert RSA_public_encrypt(fr.len.cint, frdata, todata, rsa, RSA_PKCS1_PADDING) != -1 doAssert RSA_public_encrypt(fr.len.cint, frdata, todata, rsa, RSA_PKCS1_PADDING) != -1
RSA_free(rsa) RSA_free(rsa)
@ -26,8 +26,8 @@ proc rasPrivateDecrypt(fr: string): string =
doAssert BIO_free(bio) >= 0 doAssert BIO_free(bio) >= 0
let rsaLen = RSA_size(rsa) let rsaLen = RSA_size(rsa)
result = newString(rsaLen) result = newString(rsaLen)
let frdata = cast[ptr cuchar](fr.cstring) let frdata = cast[ptr uint8](fr.cstring)
var todata = cast[ptr cuchar](result.cstring) var todata = cast[ptr uint8](result.cstring)
let lenOrig = RSA_private_decrypt(rsaLen, frdata, todata, rsa, RSA_PKCS1_PADDING) let lenOrig = RSA_private_decrypt(rsaLen, frdata, todata, rsa, RSA_PKCS1_PADDING)
doAssert lenOrig >= 0 and lenOrig < result.len doAssert lenOrig >= 0 and lenOrig < result.len
doAssert result[lenOrig] == '\0' doAssert result[lenOrig] == '\0'