IntegerConvertible.swift 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // IntegerConvertible.swift
  3. // CryptoSwift
  4. //
  5. // Created by Marcin Krzyzanowski on 02/06/15.
  6. // Copyright (c) 2015 Marcin Krzyzanowski. All rights reserved.
  7. //
  8. protocol BitshiftOperationsType {
  9. static func <<(lhs: Self, rhs: Self) -> Self
  10. static func >>(lhs: Self, rhs: Self) -> Self
  11. static func <<=(lhs: inout Self, rhs: Self)
  12. static func >>=(lhs: inout Self, rhs: Self)
  13. }
  14. protocol ByteConvertible {
  15. init(_ value: UInt8)
  16. init(truncatingBitPattern: UInt64)
  17. }
  18. extension Int: BitshiftOperationsType, ByteConvertible {}
  19. extension Int8: BitshiftOperationsType, ByteConvertible {}
  20. extension Int16: BitshiftOperationsType, ByteConvertible {}
  21. extension Int32: BitshiftOperationsType, ByteConvertible {}
  22. extension Int64: BitshiftOperationsType, ByteConvertible {
  23. init(truncatingBitPattern value: UInt64) {
  24. self = Int64(bitPattern: value)
  25. }
  26. }
  27. extension UInt: BitshiftOperationsType, ByteConvertible {}
  28. extension UInt8: BitshiftOperationsType, ByteConvertible {}
  29. extension UInt16: BitshiftOperationsType, ByteConvertible {}
  30. extension UInt32: BitshiftOperationsType, ByteConvertible {}
  31. extension UInt64: BitshiftOperationsType, ByteConvertible {
  32. init(truncatingBitPattern value: UInt64) {
  33. self = value
  34. }
  35. }