[ruby/openssl] Mark variables and functions as static whenever possible

https://github.com/ruby/openssl/commit/85d6b7f192
This commit is contained in:
Kazuki Yamaguchi 2024-10-30 04:03:05 +09:00 committed by git
parent cbe7bfd9a8
commit 1df63d9451
36 changed files with 70 additions and 148 deletions

View File

@ -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;

View File

@ -163,23 +163,23 @@ VALUE mASN1;
VALUE eASN1Error;
VALUE cASN1Data;
VALUE cASN1Primitive;
VALUE cASN1Constructive;
static VALUE cASN1Primitive;
static 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 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;

View File

@ -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);

View File

@ -49,7 +49,7 @@ VALUE cBN;
*
* Generic Error for all of OpenSSL::BN (big num)
*/
VALUE eBNError;
static VALUE eBNError;
/*
* Public
@ -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)

View File

@ -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()

View File

@ -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);

View File

@ -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);

View File

@ -19,8 +19,8 @@
/*
* Classes
*/
VALUE cDigest;
VALUE eDigestError;
static VALUE cDigest;
static VALUE eDigestError;
static VALUE ossl_digest_alloc(VALUE klass);
@ -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:
@ -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;

View File

@ -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);

View File

@ -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

View File

@ -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 */

View File

@ -21,8 +21,8 @@
/*
* Classes
*/
VALUE cHMAC;
VALUE eHMACError;
static VALUE cHMAC;
static VALUE eHMACError;
/*
* Public

View File

@ -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_ */

View File

@ -27,9 +27,9 @@
/*
* Classes
*/
VALUE mNetscape;
VALUE cSPKI;
VALUE eSPKIError;
static VALUE mNetscape;
static VALUE cSPKI;
static VALUE eSPKIError;
/*
* Public functions

View File

@ -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_ */

View File

@ -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)

View File

@ -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_ */

View File

@ -27,8 +27,8 @@
/*
* Classes
*/
VALUE cPKCS12;
VALUE ePKCS12Error;
static VALUE cPKCS12;
static VALUE ePKCS12Error;
/*
* Private

View File

@ -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_ */

View File

@ -53,35 +53,24 @@ void Init_ossl_pkey(void);
* RSA
*/
extern VALUE cRSA;
extern VALUE eRSAError;
void Init_ossl_rsa(void);
/*
* DSA
*/
extern VALUE cDSA;
extern VALUE eDSAError;
void Init_ossl_dsa(void);
/*
* DH
*/
extern VALUE cDH;
extern VALUE eDHError;
void Init_ossl_dh(void);
/*
* EC
*/
extern VALUE cEC;
extern VALUE eECError;
extern VALUE cEC_GROUP;
extern VALUE eEC_GROUP;
extern VALUE cEC_POINT;
extern VALUE eEC_POINT;
VALUE ossl_ec_new(EVP_PKEY *);
void Init_ossl_ec(void);
@ -136,7 +125,7 @@ static VALUE ossl_##_keytype##_set_##_group(VALUE self, VALUE v1, VALUE v2, VALU
BN_clear_free(bn1); \
BN_clear_free(bn2); \
BN_clear_free(bn3); \
ossl_raise(eBNError, NULL); \
ossl_raise(ePKeyError, "BN_dup"); \
} \
\
if (!_type##_set0_##_group(obj, bn1, bn2, bn3)) { \
@ -164,7 +153,7 @@ static VALUE ossl_##_keytype##_set_##_group(VALUE self, VALUE v1, VALUE v2) \
(orig_bn2 && !(bn2 = BN_dup(orig_bn2)))) { \
BN_clear_free(bn1); \
BN_clear_free(bn2); \
ossl_raise(eBNError, NULL); \
ossl_raise(ePKeyError, "BN_dup"); \
} \
\
if (!_type##_set0_##_group(obj, bn1, bn2)) { \

View File

@ -27,7 +27,7 @@
* Classes
*/
VALUE cDH;
VALUE eDHError;
static VALUE eDHError;
/*
* Private

View File

@ -41,7 +41,7 @@ DSA_PRIVATE(VALUE obj, OSSL_3_const DSA *dsa)
* Classes
*/
VALUE cDSA;
VALUE eDSAError;
static VALUE eDSAError;
/*
* Private

View File

@ -41,11 +41,11 @@ static const rb_data_type_t ossl_ec_point_type;
} while (0)
VALUE cEC;
VALUE eECError;
VALUE cEC_GROUP;
VALUE eEC_GROUP;
VALUE cEC_POINT;
VALUE eEC_POINT;
static VALUE eECError;
static VALUE cEC_GROUP;
static VALUE eEC_GROUP;
static VALUE cEC_POINT;
static VALUE eEC_POINT;
static ID s_GFp, s_GF2m;

View File

@ -42,7 +42,7 @@ RSA_PRIVATE(VALUE obj, OSSL_3_const RSA *rsa)
* Classes
*/
VALUE cRSA;
VALUE eRSAError;
static VALUE eRSAError;
/*
* Private

View File

@ -9,8 +9,8 @@
*/
#include "ossl.h"
VALUE mRandom;
VALUE eRandomError;
static VALUE mRandom;
static VALUE eRandomError;
/*
* call-seq:

View File

@ -10,9 +10,6 @@
#if !defined(_OSSL_RAND_H_)
#define _OSSL_RAND_H_
extern VALUE mRandom;
extern VALUE eRandomError;
void Init_ossl_rand(void);
#endif /* _OSSL_RAND_H_ */

View File

@ -35,7 +35,7 @@
VALUE mSSL;
static VALUE eSSLError;
VALUE cSSLContext;
static VALUE cSSLContext;
VALUE cSSLSocket;
static VALUE eSSLErrorWaitReadable;

View File

@ -28,7 +28,6 @@ void Init_ossl_x509(void);
* X509Attr
*/
extern VALUE cX509Attr;
extern VALUE eX509AttrError;
VALUE ossl_x509attr_new(X509_ATTRIBUTE *);
X509_ATTRIBUTE *GetX509AttrPtr(VALUE);
@ -38,7 +37,6 @@ void Init_ossl_x509attr(void);
* X509Cert
*/
extern VALUE cX509Cert;
extern VALUE eX509CertError;
VALUE ossl_x509_new(X509 *);
X509 *GetX509CertPtr(VALUE);
@ -48,9 +46,6 @@ void Init_ossl_x509cert(void);
/*
* X509CRL
*/
extern VALUE cX509CRL;
extern VALUE eX509CRLError;
VALUE ossl_x509crl_new(X509_CRL *);
X509_CRL *GetX509CRLPtr(VALUE);
void Init_ossl_x509crl(void);
@ -59,8 +54,6 @@ void Init_ossl_x509crl(void);
* X509Extension
*/
extern VALUE cX509Ext;
extern VALUE cX509ExtFactory;
extern VALUE eX509ExtError;
VALUE ossl_x509ext_new(X509_EXTENSION *);
X509_EXTENSION *GetX509ExtPtr(VALUE);
@ -69,9 +62,6 @@ void Init_ossl_x509ext(void);
/*
* X509Name
*/
extern VALUE cX509Name;
extern VALUE eX509NameError;
VALUE ossl_x509name_new(X509_NAME *);
X509_NAME *GetX509NamePtr(VALUE);
void Init_ossl_x509name(void);
@ -79,9 +69,6 @@ void Init_ossl_x509name(void);
/*
* X509Request
*/
extern VALUE cX509Req;
extern VALUE eX509ReqError;
X509_REQ *GetX509ReqPtr(VALUE);
void Init_ossl_x509req(void);
@ -89,7 +76,6 @@ void Init_ossl_x509req(void);
* X509Revoked
*/
extern VALUE cX509Rev;
extern VALUE eX509RevError;
VALUE ossl_x509revoked_new(X509_REVOKED *);
X509_REVOKED *DupX509RevokedPtr(VALUE);
@ -98,12 +84,7 @@ void Init_ossl_x509revoked(void);
/*
* X509Store and X509StoreContext
*/
extern VALUE cX509Store;
extern VALUE cX509StoreContext;
extern VALUE eX509StoreError;
X509_STORE *GetX509StorePtr(VALUE);
void Init_ossl_x509store(void);
/*

View File

@ -28,7 +28,7 @@
* Classes
*/
VALUE cX509Attr;
VALUE eX509AttrError;
static VALUE eX509AttrError;
static void
ossl_x509attr_free(void *ptr)

View File

@ -28,7 +28,7 @@
* Classes
*/
VALUE cX509Cert;
VALUE eX509CertError;
static VALUE eX509CertError;
static void
ossl_x509_free(void *ptr)

View File

@ -27,8 +27,8 @@
/*
* Classes
*/
VALUE cX509CRL;
VALUE eX509CRLError;
static VALUE cX509CRL;
static VALUE eX509CRLError;
static void
ossl_x509crl_free(void *ptr)

View File

@ -41,8 +41,8 @@
* Classes
*/
VALUE cX509Ext;
VALUE cX509ExtFactory;
VALUE eX509ExtError;
static VALUE cX509ExtFactory;
static VALUE eX509ExtError;
static void
ossl_x509ext_free(void *ptr)

View File

@ -32,8 +32,8 @@
/*
* Classes
*/
VALUE cX509Name;
VALUE eX509NameError;
static VALUE cX509Name;
static VALUE eX509NameError;
static void
ossl_x509name_free(void *ptr)

View File

@ -27,8 +27,8 @@
/*
* Classes
*/
VALUE cX509Req;
VALUE eX509ReqError;
static VALUE cX509Req;
static VALUE eX509ReqError;
static void
ossl_x509req_free(void *ptr)

View File

@ -28,7 +28,7 @@
* Classes
*/
VALUE cX509Rev;
VALUE eX509RevError;
static VALUE eX509RevError;
static void
ossl_x509rev_free(void *ptr)

View File

@ -108,9 +108,9 @@ ossl_verify_cb_call(VALUE proc, int ok, X509_STORE_CTX *ctx)
/*
* Classes
*/
VALUE cX509Store;
VALUE cX509StoreContext;
VALUE eX509StoreError;
static VALUE cX509Store;
static VALUE cX509StoreContext;
static VALUE eX509StoreError;
static void
ossl_x509store_mark(void *ptr)