Skip to content

Commit b305f05

Browse files
committed
validate required fields
1 parent bdd7a0a commit b305f05

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

CryptoLib/src/Asn1/Pkcs/ClpPkcs10CertificationRequest.pas

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ interface
5959
SBadSequenceSize = 'Bad Sequence Size: %d';
6060
SUnsupportedDigest = 'Unsupported digest algorithm: %s';
6161
SPublicKeyNotSet = 'Public key must be set before adding Subject Key Identifier';
62+
SSubjectNotSet = 'Subject must be set before calling Build';
63+
SPublicKeyRequiredForBuild = 'Public key must be set before calling Build';
6264

6365
type
6466
/// <summary>
@@ -614,6 +616,12 @@ function TECDSACertificationRequestBuilder.Build(
614616
sigAlg: IAlgorithmIdentifier;
615617
attrs: IDerTaggedObject;
616618
begin
619+
// Validate required fields
620+
if FSubject = nil then
621+
raise EInvalidOperationCryptoLibException.Create(SSubjectNotSet);
622+
if FPublicKey = nil then
623+
raise EInvalidOperationCryptoLibException.Create(SPublicKeyRequiredForBuild);
624+
617625
if not Supports(privateKey, IECPrivateKeyParameters) then
618626
raise EArgumentCryptoLibException.Create('Expected IECPrivateKeyParameters');
619627
ecPrivKey := privateKey as IECPrivateKeyParameters;
@@ -685,6 +693,12 @@ function TEdDSACertificationRequestBuilder.Build(
685693
sigAlg: IAlgorithmIdentifier;
686694
attrs: IDerTaggedObject;
687695
begin
696+
// Validate required fields
697+
if FSubject = nil then
698+
raise EInvalidOperationCryptoLibException.Create(SSubjectNotSet);
699+
if FEd25519PublicKey = nil then
700+
raise EInvalidOperationCryptoLibException.Create(SPublicKeyRequiredForBuild);
701+
688702
// Detect key type and handle appropriately
689703
if Supports(privateKey, IEd25519PrivateKeyParameters) then
690704
begin

0 commit comments

Comments
 (0)