@@ -26,6 +26,7 @@ import {AbstractSigner} from "./AbstractSigner.sol";
26
26
* mechanism to ensure the email was actually sent and received without revealing its contents. Defined by an `IVerifier` interface.
27
27
*/
28
28
library ZKEmailUtils {
29
+ using CommandUtils for bytes [];
29
30
using Strings for string ;
30
31
31
32
/// @dev Enumeration of possible email proof validation errors.
@@ -93,34 +94,25 @@ library ZKEmailUtils {
93
94
return EmailProofError.MaskedCommandLength;
94
95
} else if (emailAuthMsg.skippedCommandPrefix >= verifier.commandBytes ()) {
95
96
return EmailProofError.SkippedCommandPrefixSize;
96
- } else if (
97
- stringCase == Case.ANY
98
- ? _matchAnyCase (emailAuthMsg, template)
99
- : _matchCase (emailAuthMsg, template, stringCase)
100
- ) {
101
- return verifier.verifyEmailProof (emailAuthMsg.proof) ? EmailProofError.NoError : EmailProofError.EmailProof;
102
- } else {
97
+ } else if (! _commandMatch (emailAuthMsg, template, stringCase)) {
103
98
return EmailProofError.MismatchedCommand;
99
+ } else {
100
+ return verifier.verifyEmailProof (emailAuthMsg.proof) ? EmailProofError.NoError : EmailProofError.EmailProof;
104
101
}
105
102
}
106
103
107
- /// @dev Checks if the command matches the expected command for any string case.
108
- function _matchAnyCase (EmailAuthMsg memory emailAuthMsg , string [] memory template ) private pure returns (bool ) {
109
- return
110
- _matchCase (emailAuthMsg, template, Case.LOWERCASE) ||
111
- _matchCase (emailAuthMsg, template, Case.UPPERCASE) ||
112
- _matchCase (emailAuthMsg, template, Case.CHECKSUM);
113
- }
114
-
115
- /// @dev MUST NOT be called with `Case.ANY` to avoid unexpected behavior.
116
- function _matchCase (
104
+ function _commandMatch (
117
105
EmailAuthMsg memory emailAuthMsg ,
118
106
string [] memory template ,
119
107
Case stringCase
120
108
) private pure returns (bool ) {
109
+ bytes [] memory commandParams = emailAuthMsg.commandParams; // Not a memory copy
110
+ string memory maskedCommand = emailAuthMsg.proof.maskedCommand; // Not a memory copy
121
111
return
122
- CommandUtils.computeExpectedCommand (emailAuthMsg.commandParams, template, uint8 (stringCase)).equal (
123
- emailAuthMsg.proof.maskedCommand
124
- );
112
+ stringCase == Case.ANY
113
+ ? (commandParams.computeExpectedCommand (template, uint8 (Case.LOWERCASE)).equal (maskedCommand) ||
114
+ commandParams.computeExpectedCommand (template, uint8 (Case.UPPERCASE)).equal (maskedCommand) ||
115
+ commandParams.computeExpectedCommand (template, uint8 (Case.CHECKSUM)).equal (maskedCommand))
116
+ : commandParams.computeExpectedCommand (template, uint8 (stringCase)).equal (maskedCommand);
125
117
}
126
118
}
0 commit comments