Skip to content

Commit

Permalink
Merge pull request #814 from rhenium/ky/extension-make-static
Browse files Browse the repository at this point in the history
Various small fixes in C extension code
  • Loading branch information
rhenium authored Dec 7, 2024
2 parents 3f7b722 + 974c67f commit 3b3c950
Show file tree
Hide file tree
Showing 40 changed files with 132 additions and 207 deletions.
14 changes: 6 additions & 8 deletions ext/openssl/ossl.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ ossl_clear_error(void)
* Any errors you see here are probably due to a bug in Ruby's OpenSSL
* implementation.
*/
VALUE
static VALUE
ossl_get_errors(VALUE _)
{
VALUE ary;
Expand Down Expand Up @@ -1150,24 +1150,22 @@ Init_openssl(void)
/*
* Init components
*/
Init_ossl_asn1();
Init_ossl_bn();
Init_ossl_cipher();
Init_ossl_config();
Init_ossl_digest();
Init_ossl_engine();
Init_ossl_hmac();
Init_ossl_kdf();
Init_ossl_ns_spki();
Init_ossl_ocsp();
Init_ossl_pkcs12();
Init_ossl_pkcs7();
Init_ossl_pkey();
Init_ossl_provider();
Init_ossl_rand();
Init_ossl_ssl();
#ifndef OPENSSL_NO_TS
Init_ossl_ts();
#endif
Init_ossl_x509();
Init_ossl_ocsp();
Init_ossl_engine();
Init_ossl_provider();
Init_ossl_asn1();
Init_ossl_kdf();
}
12 changes: 5 additions & 7 deletions ext/openssl/ossl.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <openssl/dsa.h>
#include <openssl/evp.h>
#include <openssl/dh.h>
#include "openssl_missing.h"

#ifndef LIBRESSL_VERSION_NUMBER
# define OSSL_IS_LIBRESSL 0
Expand Down Expand Up @@ -178,28 +179,25 @@ extern VALUE dOSSL;
/*
* Include all parts
*/
#include "openssl_missing.h"
#include "ossl_asn1.h"
#include "ossl_bio.h"
#include "ossl_bn.h"
#include "ossl_cipher.h"
#include "ossl_config.h"
#include "ossl_digest.h"
#include "ossl_engine.h"
#include "ossl_hmac.h"
#include "ossl_kdf.h"
#include "ossl_ns_spki.h"
#include "ossl_ocsp.h"
#include "ossl_pkcs12.h"
#include "ossl_pkcs7.h"
#include "ossl_pkey.h"
#include "ossl_provider.h"
#include "ossl_rand.h"
#include "ossl_ssl.h"
#ifndef OPENSSL_NO_TS
#include "ossl_ts.h"
#endif
#include "ossl_ts.h"
#include "ossl_x509.h"
#include "ossl_engine.h"
#include "ossl_provider.h"
#include "ossl_kdf.h"

void Init_openssl(void);

Expand Down
34 changes: 17 additions & 17 deletions ext/openssl/ossl_asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,23 +163,23 @@ VALUE mASN1;
VALUE eASN1Error;

VALUE cASN1Data;
VALUE cASN1Primitive;
VALUE cASN1Constructive;

VALUE cASN1EndOfContent;
VALUE cASN1Boolean; /* BOOLEAN */
VALUE cASN1Integer, cASN1Enumerated; /* INTEGER */
VALUE cASN1BitString; /* BIT STRING */
VALUE cASN1OctetString, cASN1UTF8String; /* STRINGs */
VALUE cASN1NumericString, cASN1PrintableString;
VALUE cASN1T61String, cASN1VideotexString;
VALUE cASN1IA5String, cASN1GraphicString;
VALUE cASN1ISO64String, cASN1GeneralString;
VALUE cASN1UniversalString, cASN1BMPString;
VALUE cASN1Null; /* NULL */
VALUE cASN1ObjectId; /* OBJECT IDENTIFIER */
VALUE cASN1UTCTime, cASN1GeneralizedTime; /* TIME */
VALUE cASN1Sequence, cASN1Set; /* CONSTRUCTIVE */
static VALUE cASN1Primitive;
static VALUE cASN1Constructive;

static VALUE cASN1EndOfContent;
static VALUE cASN1Boolean; /* BOOLEAN */
static VALUE cASN1Integer, cASN1Enumerated; /* INTEGER */
static VALUE cASN1BitString; /* BIT STRING */
static VALUE cASN1OctetString, cASN1UTF8String; /* STRINGs */
static VALUE cASN1NumericString, cASN1PrintableString;
static VALUE cASN1T61String, cASN1VideotexString;
static VALUE cASN1IA5String, cASN1GraphicString;
static VALUE cASN1ISO64String, cASN1GeneralString;
static VALUE cASN1UniversalString, cASN1BMPString;
static VALUE cASN1Null; /* NULL */
static VALUE cASN1ObjectId; /* OBJECT IDENTIFIER */
static VALUE cASN1UTCTime, cASN1GeneralizedTime; /* TIME */
static VALUE cASN1Sequence, cASN1Set; /* CONSTRUCTIVE */

static VALUE sym_IMPLICIT, sym_EXPLICIT;
static VALUE sym_UNIVERSAL, sym_APPLICATION, sym_CONTEXT_SPECIFIC, sym_PRIVATE;
Expand Down
18 changes: 0 additions & 18 deletions ext/openssl/ossl_asn1.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,6 @@ extern VALUE mASN1;
extern VALUE eASN1Error;

extern VALUE cASN1Data;
extern VALUE cASN1Primitive;
extern VALUE cASN1Constructive;

extern VALUE cASN1Boolean; /* BOOLEAN */
extern VALUE cASN1Integer, cASN1Enumerated; /* INTEGER */
extern VALUE cASN1BitString; /* BIT STRING */
extern VALUE cASN1OctetString, cASN1UTF8String; /* STRINGs */
extern VALUE cASN1NumericString, cASN1PrintableString;
extern VALUE cASN1T61String, cASN1VideotexString;
extern VALUE cASN1IA5String, cASN1GraphicString;
extern VALUE cASN1ISO64String, cASN1GeneralString;
extern VALUE cASN1UniversalString, cASN1BMPString;
extern VALUE cASN1Null; /* NULL */
extern VALUE cASN1ObjectId; /* OBJECT IDENTIFIER */
extern VALUE cASN1UTCTime, cASN1GeneralizedTime; /* TIME */
extern VALUE cASN1Sequence, cASN1Set; /* CONSTRUCTIVE */

extern VALUE cASN1EndOfContent; /* END OF CONTENT */

void Init_ossl_asn1(void);

Expand Down
8 changes: 4 additions & 4 deletions ext/openssl/ossl_bn.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ VALUE cBN;
*
* Generic Error for all of OpenSSL::BN (big num)
*/
VALUE eBNError;
static VALUE eBNError;

/*
* Public
Expand Down Expand Up @@ -152,19 +152,19 @@ ossl_bn_value_ptr(volatile VALUE *ptr)
*/

#ifdef HAVE_RB_EXT_RACTOR_SAFE
void
static void
ossl_bn_ctx_free(void *ptr)
{
BN_CTX *ctx = (BN_CTX *)ptr;
BN_CTX_free(ctx);
}

struct rb_ractor_local_storage_type ossl_bn_ctx_key_type = {
static struct rb_ractor_local_storage_type ossl_bn_ctx_key_type = {
NULL, // mark
ossl_bn_ctx_free,
};

rb_ractor_local_key_t ossl_bn_ctx_key;
static rb_ractor_local_key_t ossl_bn_ctx_key;

BN_CTX *
ossl_bn_ctx_get(void)
Expand Down
1 change: 0 additions & 1 deletion ext/openssl/ossl_bn.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#define _OSSL_BN_H_

extern VALUE cBN;
extern VALUE eBNError;

BN_CTX *ossl_bn_ctx_get(void);
#define ossl_bn_ctx ossl_bn_ctx_get()
Expand Down
4 changes: 2 additions & 2 deletions ext/openssl/ossl_cipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
/*
* Classes
*/
VALUE cCipher;
VALUE eCipherError;
static VALUE cCipher;
static VALUE eCipherError;
static ID id_auth_tag_len, id_key_set;

static VALUE ossl_cipher_alloc(VALUE klass);
Expand Down
3 changes: 0 additions & 3 deletions ext/openssl/ossl_cipher.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
#if !defined(_OSSL_CIPHER_H_)
#define _OSSL_CIPHER_H_

extern VALUE cCipher;
extern VALUE eCipherError;

const EVP_CIPHER *ossl_evp_get_cipherbyname(VALUE);
VALUE ossl_cipher_new(const EVP_CIPHER *);
void Init_ossl_cipher(void);
Expand Down
8 changes: 4 additions & 4 deletions ext/openssl/ossl_digest.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
/*
* Classes
*/
VALUE cDigest;
VALUE eDigestError;
static VALUE cDigest;
static VALUE eDigestError;

static VALUE ossl_digest_alloc(VALUE klass);

Expand Down Expand Up @@ -96,7 +96,7 @@ ossl_digest_alloc(VALUE klass)
return TypedData_Wrap_Struct(klass, &ossl_digest_type, 0);
}

VALUE ossl_digest_update(VALUE, VALUE);
static VALUE ossl_digest_update(VALUE, VALUE);

/*
* call-seq:
Expand Down Expand Up @@ -225,7 +225,7 @@ ossl_digest_reset(VALUE self)
* result = digest.digest
*
*/
VALUE
static VALUE
ossl_digest_update(VALUE self, VALUE data)
{
EVP_MD_CTX *ctx;
Expand Down
3 changes: 0 additions & 3 deletions ext/openssl/ossl_digest.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
#if !defined(_OSSL_DIGEST_H_)
#define _OSSL_DIGEST_H_

extern VALUE cDigest;
extern VALUE eDigestError;

const EVP_MD *ossl_evp_get_digestbyname(VALUE);
VALUE ossl_digest_new(const EVP_MD *);
void Init_ossl_digest(void);
Expand Down
4 changes: 2 additions & 2 deletions ext/openssl/ossl_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
*
* See also, https://www.openssl.org/docs/crypto/engine.html
*/
VALUE cEngine;
static VALUE cEngine;
/* Document-class: OpenSSL::Engine::EngineError
*
* This is the generic exception for OpenSSL::Engine related errors
*/
VALUE eEngineError;
static VALUE eEngineError;

/*
* Private
Expand Down
3 changes: 0 additions & 3 deletions ext/openssl/ossl_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
#if !defined(OSSL_ENGINE_H)
#define OSSL_ENGINE_H

extern VALUE cEngine;
extern VALUE eEngineError;

void Init_ossl_engine(void);

#endif /* OSSL_ENGINE_H */
4 changes: 2 additions & 2 deletions ext/openssl/ossl_hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
/*
* Classes
*/
VALUE cHMAC;
VALUE eHMACError;
static VALUE cHMAC;
static VALUE eHMACError;

/*
* Public
Expand Down
3 changes: 0 additions & 3 deletions ext/openssl/ossl_hmac.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
#if !defined(_OSSL_HMAC_H_)
#define _OSSL_HMAC_H_

extern VALUE cHMAC;
extern VALUE eHMACError;

void Init_ossl_hmac(void);

#endif /* _OSSL_HMAC_H_ */
10 changes: 5 additions & 5 deletions ext/openssl/ossl_ns_spki.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
/*
* Classes
*/
VALUE mNetscape;
VALUE cSPKI;
VALUE eSPKIError;
static VALUE mNetscape;
static VALUE cSPKI;
static VALUE eSPKIError;

/*
* Public functions
Expand Down Expand Up @@ -115,11 +115,11 @@ ossl_spki_to_der(VALUE self)

GetSPKI(self, spki);
if ((len = i2d_NETSCAPE_SPKI(spki, NULL)) <= 0)
ossl_raise(eX509CertError, NULL);
ossl_raise(eSPKIError, "i2d_NETSCAPE_SPKI");
str = rb_str_new(0, len);
p = (unsigned char *)RSTRING_PTR(str);
if (i2d_NETSCAPE_SPKI(spki, &p) <= 0)
ossl_raise(eX509CertError, NULL);
ossl_raise(eSPKIError, "i2d_NETSCAPE_SPKI");
ossl_str_adjust(str, p);

return str;
Expand Down
4 changes: 0 additions & 4 deletions ext/openssl/ossl_ns_spki.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
#if !defined(_OSSL_NS_SPKI_H_)
#define _OSSL_NS_SPKI_H_

extern VALUE mNetscape;
extern VALUE cSPKI;
extern VALUE eSPKIError;

void Init_ossl_ns_spki(void);

#endif /* _OSSL_NS_SPKI_H_ */
14 changes: 7 additions & 7 deletions ext/openssl/ossl_ocsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@
if(!(cid)) ossl_raise(rb_eRuntimeError, "Cert ID wasn't initialized!"); \
} while (0)

VALUE mOCSP;
VALUE eOCSPError;
VALUE cOCSPReq;
VALUE cOCSPRes;
VALUE cOCSPBasicRes;
VALUE cOCSPSingleRes;
VALUE cOCSPCertId;
static VALUE mOCSP;
static VALUE eOCSPError;
static VALUE cOCSPReq;
static VALUE cOCSPRes;
static VALUE cOCSPBasicRes;
static VALUE cOCSPSingleRes;
static VALUE cOCSPCertId;

static void
ossl_ocsp_request_free(void *ptr)
Expand Down
7 changes: 0 additions & 7 deletions ext/openssl/ossl_ocsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@
#if !defined(_OSSL_OCSP_H_)
#define _OSSL_OCSP_H_

#if !defined(OPENSSL_NO_OCSP)
extern VALUE mOCSP;
extern VALUE cOCSPReq;
extern VALUE cOCSPRes;
extern VALUE cOCSPBasicRes;
#endif

void Init_ossl_ocsp(void);

#endif /* _OSSL_OCSP_H_ */
4 changes: 2 additions & 2 deletions ext/openssl/ossl_pkcs12.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
/*
* Classes
*/
VALUE cPKCS12;
VALUE ePKCS12Error;
static VALUE cPKCS12;
static VALUE ePKCS12Error;

/*
* Private
Expand Down
3 changes: 0 additions & 3 deletions ext/openssl/ossl_pkcs12.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#if !defined(_OSSL_PKCS12_H_)
#define _OSSL_PKCS12_H_

extern VALUE cPKCS12;
extern VALUE ePKCS12Error;

void Init_ossl_pkcs12(void);

#endif /* _OSSL_PKCS12_H_ */
Loading

0 comments on commit 3b3c950

Please sign in to comment.