This commit is contained in:
		
							parent
							
								
									4241d4545c
								
							
						
					
					
						commit
						480a7eeff2
					
				
							
								
								
									
										7626
									
								
								tests/resources/reference-tests.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7626
									
								
								tests/resources/reference-tests.ts
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										29
									
								
								tests/romulus-m-reference.test.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								tests/romulus-m-reference.test.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,29 @@ | ||||
| import { referenceTests } from './resources/reference-tests' | ||||
| import { cryptoAeadDecrypt, cryptoAeadEncrypt } from '../src/romulus-m' | ||||
| 
 | ||||
| function parseHexString (string: string): number[] { | ||||
|   const ret = [] | ||||
|   for (let i = 0; i < string.length; i += 2) { | ||||
|     ret.push(parseInt(string.slice(i, i + 2), 16)) | ||||
|   } | ||||
| 
 | ||||
|   return ret | ||||
| } | ||||
| 
 | ||||
| test.each(referenceTests)('Perform encryption using reference test %#.', (key, nonce, plaintext, associatedData, ciphertext) => { | ||||
|   // When
 | ||||
|   const result = cryptoAeadEncrypt(parseHexString(plaintext), parseHexString(associatedData), parseHexString(nonce), parseHexString(key)) | ||||
| 
 | ||||
|   // Then
 | ||||
|   const expectedResult = parseHexString(ciphertext) | ||||
|   expect(result).toMatchObject(expectedResult) | ||||
| }) | ||||
| 
 | ||||
| test.each(referenceTests)('Perform decryption using reference test %#.', (key, nonce, plaintext, associatedData, ciphertext) => { | ||||
|   // When
 | ||||
|   const result = cryptoAeadDecrypt(parseHexString(ciphertext), parseHexString(associatedData), parseHexString(nonce), parseHexString(key)) | ||||
| 
 | ||||
|   // Then
 | ||||
|   const expectedResult = parseHexString(plaintext) | ||||
|   expect(result).toMatchObject(expectedResult) | ||||
| }) | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user