BCertificate: fixup the API
* Add an operator== and a copy constructor * Make the getters const so they are easier to use
This commit is contained in:
parent
ba307a12db
commit
6c32f50a64
@ -12,30 +12,30 @@
|
|||||||
|
|
||||||
class BCertificate {
|
class BCertificate {
|
||||||
public:
|
public:
|
||||||
|
BCertificate(const BCertificate& other);
|
||||||
~BCertificate();
|
~BCertificate();
|
||||||
|
|
||||||
int Version();
|
int Version() const;
|
||||||
|
|
||||||
time_t StartDate();
|
time_t StartDate() const;
|
||||||
time_t ExpirationDate();
|
time_t ExpirationDate() const;
|
||||||
|
|
||||||
bool IsValidAuthority();
|
bool IsValidAuthority() const;
|
||||||
bool IsSelfSigned();
|
bool IsSelfSigned() const;
|
||||||
|
|
||||||
BString Issuer();
|
BString Issuer() const;
|
||||||
BString Subject();
|
BString Subject() const;
|
||||||
BString SignatureAlgorithm();
|
BString SignatureAlgorithm() const;
|
||||||
|
|
||||||
BString String();
|
BString String() const;
|
||||||
|
|
||||||
|
bool operator==(const BCertificate& other);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class BSecureSocket::Private;
|
friend class BSecureSocket::Private;
|
||||||
class Private;
|
class Private;
|
||||||
BCertificate(Private* data);
|
BCertificate(Private* data);
|
||||||
|
|
||||||
BCertificate(const BCertificate& other);
|
|
||||||
// copy-construction not allowed
|
|
||||||
|
|
||||||
Private* fPrivate;
|
Private* fPrivate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -58,6 +58,12 @@ BCertificate::BCertificate(Private* data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BCertificate::BCertificate(const BCertificate& other)
|
||||||
|
{
|
||||||
|
fPrivate = new<std::nothrow>BCertificate::Private(other.fPrivate);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BCertificate::~BCertificate()
|
BCertificate::~BCertificate()
|
||||||
{
|
{
|
||||||
delete fPrivate;
|
delete fPrivate;
|
||||||
@ -65,42 +71,42 @@ BCertificate::~BCertificate()
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
BCertificate::Version()
|
BCertificate::Version() const
|
||||||
{
|
{
|
||||||
return X509_get_version(fPrivate->fX509) + 1;
|
return X509_get_version(fPrivate->fX509) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
time_t
|
time_t
|
||||||
BCertificate::StartDate()
|
BCertificate::StartDate() const
|
||||||
{
|
{
|
||||||
return parse_ASN1(X509_get_notBefore(fPrivate->fX509));
|
return parse_ASN1(X509_get_notBefore(fPrivate->fX509));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
time_t
|
time_t
|
||||||
BCertificate::ExpirationDate()
|
BCertificate::ExpirationDate() const
|
||||||
{
|
{
|
||||||
return parse_ASN1(X509_get_notAfter(fPrivate->fX509));
|
return parse_ASN1(X509_get_notAfter(fPrivate->fX509));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BCertificate::IsValidAuthority()
|
BCertificate::IsValidAuthority() const
|
||||||
{
|
{
|
||||||
return X509_check_ca(fPrivate->fX509) > 0;
|
return X509_check_ca(fPrivate->fX509) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BCertificate::IsSelfSigned()
|
BCertificate::IsSelfSigned() const
|
||||||
{
|
{
|
||||||
return X509_check_issued(fPrivate->fX509, fPrivate->fX509) == X509_V_OK;
|
return X509_check_issued(fPrivate->fX509, fPrivate->fX509) == X509_V_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BString
|
BString
|
||||||
BCertificate::Issuer()
|
BCertificate::Issuer() const
|
||||||
{
|
{
|
||||||
X509_NAME* name = X509_get_issuer_name(fPrivate->fX509);
|
X509_NAME* name = X509_get_issuer_name(fPrivate->fX509);
|
||||||
return decode_X509_NAME(name);
|
return decode_X509_NAME(name);
|
||||||
@ -108,7 +114,7 @@ BCertificate::Issuer()
|
|||||||
|
|
||||||
|
|
||||||
BString
|
BString
|
||||||
BCertificate::Subject()
|
BCertificate::Subject() const
|
||||||
{
|
{
|
||||||
X509_NAME* name = X509_get_subject_name(fPrivate->fX509);
|
X509_NAME* name = X509_get_subject_name(fPrivate->fX509);
|
||||||
return decode_X509_NAME(name);
|
return decode_X509_NAME(name);
|
||||||
@ -116,7 +122,7 @@ BCertificate::Subject()
|
|||||||
|
|
||||||
|
|
||||||
BString
|
BString
|
||||||
BCertificate::SignatureAlgorithm()
|
BCertificate::SignatureAlgorithm() const
|
||||||
{
|
{
|
||||||
int algorithmIdentifier = OBJ_obj2nid(
|
int algorithmIdentifier = OBJ_obj2nid(
|
||||||
fPrivate->fX509->cert_info->key->algor->algorithm);
|
fPrivate->fX509->cert_info->key->algor->algorithm);
|
||||||
@ -130,7 +136,7 @@ BCertificate::SignatureAlgorithm()
|
|||||||
|
|
||||||
|
|
||||||
BString
|
BString
|
||||||
BCertificate::String()
|
BCertificate::String() const
|
||||||
{
|
{
|
||||||
BIO *buffer = BIO_new(BIO_s_mem());
|
BIO *buffer = BIO_new(BIO_s_mem());
|
||||||
X509_print_ex(buffer, fPrivate->fX509, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
|
X509_print_ex(buffer, fPrivate->fX509, XN_FLAG_COMPAT, X509_FLAG_COMPAT);
|
||||||
@ -144,18 +150,36 @@ BCertificate::String()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BCertificate::operator==(const BCertificate& other)
|
||||||
|
{
|
||||||
|
return X509_cmp(fPrivate.fX509, other.fPrivate.fX509) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - BCertificate::Private
|
// #pragma mark - BCertificate::Private
|
||||||
|
|
||||||
|
|
||||||
BCertificate::Private::Private(X509* data)
|
BCertificate::Private::Private(X509* data)
|
||||||
: fX509(data)
|
: fX509(X509_dup(data))
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BCertificate::Private::~Private()
|
||||||
|
{
|
||||||
|
sk_X509_pop_free(chain, X509_free)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
|
||||||
|
BCertificate::BCertificate(const BCertificate& other)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
BCertificate::BCertificate(Private* data)
|
BCertificate::BCertificate(Private* data)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -167,59 +191,65 @@ BCertificate::~BCertificate()
|
|||||||
|
|
||||||
|
|
||||||
time_t
|
time_t
|
||||||
BCertificate::StartDate()
|
BCertificate::StartDate() const
|
||||||
{
|
{
|
||||||
return B_NOT_SUPPORTED;
|
return B_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
time_t
|
time_t
|
||||||
BCertificate::ExpirationDate()
|
BCertificate::ExpirationDate() const
|
||||||
{
|
{
|
||||||
return B_NOT_SUPPORTED;
|
return B_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BCertificate::IsValidAuthority()
|
BCertificate::IsValidAuthority() const
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
BCertificate::Version()
|
BCertificate::Version() const
|
||||||
{
|
{
|
||||||
return B_NOT_SUPPORTED;
|
return B_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BString
|
BString
|
||||||
BCertificate::Issuer()
|
BCertificate::Issuer() const
|
||||||
{
|
{
|
||||||
return BString();
|
return BString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BString
|
BString
|
||||||
BCertificate::Subject()
|
BCertificate::Subject() const
|
||||||
{
|
{
|
||||||
return BString();
|
return BString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BString
|
BString
|
||||||
BCertificate::SignatureAlgorithm()
|
BCertificate::SignatureAlgorithm() const
|
||||||
{
|
{
|
||||||
return BString();
|
return BString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BString
|
BString
|
||||||
BCertificate::String()
|
BCertificate::String() const
|
||||||
{
|
{
|
||||||
return BString();
|
return BString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BCertificate::operator==(const BCertificate& other)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
class BCertificate::Private {
|
class BCertificate::Private {
|
||||||
public:
|
public:
|
||||||
Private(X509* data);
|
Private(X509* data);
|
||||||
|
~Private();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
X509* fX509;
|
X509* fX509;
|
||||||
|
Loading…
Reference in New Issue
Block a user