diff options
author | michael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2019-01-09 10:19:27 +0000 |
---|---|---|
committer | michael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2> | 2019-01-09 10:19:27 +0000 |
commit | 54862c2230737a775371c7f7e871a30e81748339 (patch) | |
tree | 73b074c60aa9b94f8e5d3333a5e8abfe2371351e /packages | |
parent | 9e7cddace288d0ebe1a7d2301d4b6dbad8ba4928 (diff) | |
download | fpc-54862c2230737a775371c7f7e871a30e81748339.tar.gz |
* Cosmetic patch from Silvio
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@40812 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages')
-rw-r--r-- | packages/gnutls/examples/privkey.pp | 47 | ||||
-rw-r--r-- | packages/gnutls/src/gnutls.pp | 27 |
2 files changed, 45 insertions, 29 deletions
diff --git a/packages/gnutls/examples/privkey.pp b/packages/gnutls/examples/privkey.pp index 30250925c1..d82c3141ca 100644 --- a/packages/gnutls/examples/privkey.pp +++ b/packages/gnutls/examples/privkey.pp @@ -1,8 +1,8 @@ { - Simple Low-level example showing how to generate a - RSA private key (4096 bytes) using the GnuTLS binding. + Simple low-level example for how generate a RSA private key (4096 bytes) using + the GnuTLS binding. - Author: Silvio Clecio (silvioprog) + Author(s): Silvio Clecio (silvioprog), Michael Van Canneyt Date: Mon Jan 7 01:36:18 -03 2019 GnuTLS version: 3.4+ } @@ -18,43 +18,32 @@ uses gnutls; type -{ cchar = Byte; - Pcchar = PAnsiChar; - Pcsize_t = PNativeUInt; - Pcvoid = Pointer;} - EGnuTLS = Exception; - -procedure CheckRet(ret: cint); -var - P: Pchar; - S: string; +procedure TLSCheckRet(Aret: cint); inline; begin - if ret = GNUTLS_E_SUCCESS then - Exit; - P := gnutls_strerror(ret); - S:=StrPas(P);// SetString(S, @P[0], Length(Pcchar(@P[0]))); - SetCodePage(RawByteString(S), CP_UTF8, False); - raise EGnuTLS.Create(S); + if Aret <> GNUTLS_E_SUCCESS then + raise EGnuTLS.Create(gnutls_strerror(Aret)); end; var - priv_key: String; - priv_key_size: cuint = SizeOf(priv_key); + priv_key: AnsiString = ''; + priv_key_size: cuint; key: Tgnutls_x509_privkey_t; - begin LoadGnuTLS; + Assert(GnuTLSLoaded); try - Assert(GnuTLSLoaded); try - CheckRet(gnutls_x509_privkey_init(@key)); - priv_key_size := gnutls_sec_param_to_pk_bits(GNUTLS_PK_RSA, GNUTLS_SEC_PARAM_HIGH); - setLength(Priv_key,priv_key_size*2); - CheckRet(gnutls_x509_privkey_generate(key, GNUTLS_PK_RSA, priv_key_size, 0)); - CheckRet(gnutls_x509_privkey_export(key, GNUTLS_X509_FMT_PEM, @priv_key[1], @priv_key_size)); - setLength(Priv_key,priv_key_size); + TLSCheckRet(gnutls_x509_privkey_init(@key)); + priv_key_size := gnutls_sec_param_to_pk_bits(GNUTLS_PK_RSA, + GNUTLS_SEC_PARAM_HIGH); + SetLength(priv_key, Pred(priv_key_size)); + TLSCheckRet(gnutls_x509_privkey_generate(key, GNUTLS_PK_RSA, + priv_key_size, 0)); + TLSCheckRet(gnutls_x509_privkey_export(key, GNUTLS_X509_FMT_PEM, + @priv_key[1], @priv_key_size)); + SetLength(priv_key, Pred(priv_key_size)); WriteLn(priv_key); except diff --git a/packages/gnutls/src/gnutls.pp b/packages/gnutls/src/gnutls.pp index 61d179da79..1ebe48adfe 100644 --- a/packages/gnutls/src/gnutls.pp +++ b/packages/gnutls/src/gnutls.pp @@ -1,5 +1,21 @@ +{ + This file is part of the Free Pascal run time library. + Copyright (c) 2019 by Michael Van Canneyt and Silvio Clecio (silvioprog), + members of the Free Pascal development team + + Low-level binding for GnuTLS library. + + See the file COPYING.FPC, included in this distribution, + for details about the copyright. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + + **********************************************************************} {$mode objfpc} + unit gnutls; interface @@ -721,6 +737,17 @@ const GNUTLS_PKCS_USE_PBES2_AES_192 = GNUTLS_PKCS_PBES2_AES_192; GNUTLS_PKCS_USE_PBES2_AES_256 = GNUTLS_PKCS_PBES2_AES_256; + // when the key is to be used for signing: + GNUTLS_KEY_DIGITAL_SIGNATURE = 128; + GNUTLS_KEY_NON_REPUDIATION = 64; + // when the key is to be used for encryption: + GNUTLS_KEY_KEY_ENCIPHERMENT = 32; + GNUTLS_KEY_DATA_ENCIPHERMENT = 16; + GNUTLS_KEY_KEY_AGREEMENT = 8; + GNUTLS_KEY_KEY_CERT_SIGN = 4; + GNUTLS_KEY_CRL_SIGN = 2; + GNUTLS_KEY_ENCIPHER_ONLY = 1; + GNUTLS_KEY_DECIPHER_ONLY = 32768; { Pointers to basic pascal types, inserted by h2pas conversion program.} Type |