@@ -33,24 +33,21 @@ class Module implements ModuleInterface, DictionaryInterface, DocumentInterface
3333 protected $ certificateId ;
3434
3535 /**
36- * A Time based One Time Pin (TOTP) generated by a compatible app such as Google Authenticator, Microsoft Authenticator etc'.
36+ * A Time based One Time Pin (TOTP) generated by a compatible app such as Google Authenticator, Microsoft
37+ * Authenticator etc.
38+ *
3739 * @var null|string
3840 */
3941 protected $ otp ;
4042
4143 /**
4244 * The Signing Activation Data (SAD) token obtained in an earlier authorise request.
45+ *
46+ * @see Client::authorize()
4347 * @var null|string
4448 */
4549 protected $ sad ;
4650
47- /**
48- * Signing method to be used, either 'otp' or 'sad'
49- * Default: otp
50- * @var string
51- */
52- protected $ signingMethod = 'otp ' ;
53-
5451 /**
5552 * @var string
5653 */
@@ -89,29 +86,28 @@ public function setSigningAlgorithm(string $algorithm)
8986 $ this ->_getPadesModule ()->setDigest ($ hashingAlgorithm );
9087 }
9188
89+ /**
90+ * Set a Time based One Time Pin (TOTP) generated by a compatible app such as Google Authenticator, Microsoft
91+ * Authenticator etc.
92+ *
93+ * @param string $otp
94+ * @return void
95+ */
9296 public function setOtp (string $ otp ): void
9397 {
9498 $ this ->otp = $ otp ;
9599 }
96100
97- public function setSad (string $ sad ): void
98- {
99- $ this ->sad = $ sad ;
100- }
101-
102101 /**
103- * Sets the desired signing method to use on createSignature method
102+ * Set a Signing Activation Data (SAD) token obtained in an earlier authorise request.
103+ *
104+ * @see Client::authorize()
105+ * @param string $sad
106+ * @return void
104107 */
105- public function setSigningMethod ( $ method )
108+ public function setSad ( string $ sad ): void
106109 {
107- $ possible = ['otp ' ,'sad ' ];
108-
109- if ( ! in_array ($ method , $ possible ) )
110- {
111- throw new InvalidArgumentException ('Invalid signing method! you can only choose beteen: ' . implode (', ' , $ possible ));
112- }
113-
114- $ this ->signingMethod = $ method ;
110+ $ this ->sad = $ sad ;
115111 }
116112
117113 public function getCertificate ()
@@ -138,34 +134,30 @@ public function createSignature(SetaPDF_Core_Reader_FilePath $tmpPath)
138134
139135 $ hashData = hash ($ padesDigest , $ padesModule ->getDataToSign ($ tmpPath ), true );
140136
141- if ( $ this ->signingMethod == 'sad ' ) {
142- // Sign using SAD
143- if ($ this ->sad === null ) {
144- throw new \BadMethodCallException ('Missing SAD! Did you perform /authorize request before? ' );
145- }
137+ if ($ this ->sad !== null && $ this ->otp !== null ) {
138+ throw new \BadMethodCallException ('SAD and OTP given! You must only use one. ' );
139+ }
146140
141+ if ($ this ->sad !== null ) {
142+ // Sign using SAD
147143 $ signatureValue = $ this ->client ->signWithSad (
148144 $ this ->certificateId ,
149145 $ this ->signingAlgorithm ,
150146 $ hashData ,
151147 $ this ->sad
152148 );
153- }
154- else {
149+ } elseif ($ this ->otp !== null ) {
155150 // Sign using OTP
156- if ($ this ->otp === null ) {
157- throw new \BadMethodCallException ('Missing OTP! ' );
158- }
159-
160151 $ signatureValue = $ this ->client ->signWithOtp (
161152 $ this ->certificateId ,
162153 $ this ->signingAlgorithm ,
163154 $ hashData ,
164155 $ this ->otp
165156 );
157+ } else {
158+ throw new \BadMethodCallException ('Missing SAD/OTP! Please use setOtp() OR setSad() before. ' );
166159 }
167160
168-
169161 if (\in_array ($ this ->signingAlgorithm , ['ES256 ' , 'ES384 ' , 'ES512 ' ], true )) {
170162 // THIS NEEDS TO BE USED TO FIX EC SIGNATURES
171163 $ len = strlen ($ signatureValue );
0 commit comments