import sys sys.path.append('./fastpbkdf2') import testdata hashes = dict( sha1 = 'pbkdf2_hmac_sha1', sha256 = 'pbkdf2_hmac_sha256', sha512 = 'pbkdf2_hmac_sha512' ) def bb(b): if b.isalnum(): return 'b"%s"' % b else: return 'b"%s"' % ''.join('\\x%02x' % ord(c) for c in b) print """// generated by gentests.py; do not edit extern crate fastpbkdf2; use fastpbkdf2::{pbkdf2_hmac_sha1, pbkdf2_hmac_sha256, pbkdf2_hmac_sha512}; #[cfg(test)] fn check(a: &[u8], b: &[u8]) { assert_eq!(a.len(), b.len()); for i in 0..a.len() { assert_eq!(a[i], b[i]); } } """ for hash, tests in sorted(testdata.tests.items()): print '#[test]' print 'fn test_%s() {' % hash fn = hashes[hash] for t in tests: print ' {' print ' let mut out = [0u8; %d];' % len(t['output']) print ' %s(%s, %s, %d, &mut out);' % (fn, bb(t['password']), bb(t['salt']), t['iterations']) print ' check(&out, %s);' % bb(t['output']) print ' }' print '}' print