Access.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // Access.swift
  3. // CryptoSwift
  4. //
  5. // Created by Marcin Krzyzanowski on 06/08/16.
  6. // Copyright © 2016 Marcin Krzyzanowski. All rights reserved.
  7. //
  8. import XCTest
  9. import CryptoSwift
  10. class Access: XCTestCase {
  11. let cipher = try! AES(key: Array<UInt8>(hex: "b1b2b3b3b3b3b3b3b1b2b3b3b3b3b3b3"))
  12. let authenticator = Authenticator.HMAC(key: Array<UInt8>(hex: "b1b2b3b3b3b3b3b3b1b2b3b3b3b3b3b3"), variant: .sha1)
  13. func testCRC() {
  14. let _ = CRC.crc32([1,2,3])
  15. let _ = CRC.crc16([1,2,3])
  16. }
  17. func testHash() {
  18. let _ = Hash.md5([1,2,3])
  19. let _ = Hash.sha1([1,2,3])
  20. let _ = Hash.sha224([1,2,3])
  21. let _ = Hash.sha256([1,2,3])
  22. let _ = Hash.sha384([1,2,3])
  23. let _ = Hash.sha512([1,2,3])
  24. }
  25. func testArrayExtension() {
  26. let array = Array<UInt8>(hex: "b1b2b3b3b3b3b3b3b1b2b3b3b3b3b3b3")
  27. let _ = array.toHexString()
  28. let _ = array.md5()
  29. let _ = array.sha1()
  30. let _ = array.sha256()
  31. let _ = array.sha384()
  32. let _ = array.sha512()
  33. let _ = array.crc32()
  34. let _ = array.crc16()
  35. do {
  36. let _ = try array.encrypt(cipher: cipher)
  37. let _ = try array.decrypt(cipher: cipher)
  38. let _ = try array.authenticate(with: authenticator)
  39. } catch {
  40. XCTFail(error.localizedDescription)
  41. }
  42. }
  43. func testCollectionExtension() {
  44. }
  45. func testStringExtension() {
  46. let string = "foofoobarbar"
  47. let _ = string.md5()
  48. let _ = string.sha1()
  49. let _ = string.sha224()
  50. let _ = string.sha256()
  51. let _ = string.sha384()
  52. let _ = string.sha512()
  53. let _ = string.crc16()
  54. let _ = string.crc32()
  55. do {
  56. let _ = try string.encrypt(cipher: cipher)
  57. let _ = try string.authenticate(with: authenticator)
  58. } catch {
  59. XCTFail(error.localizedDescription)
  60. }
  61. }
  62. }