IntegerConvertible.swift 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. func <<(lhs: Self, rhs: Self) -> Self
  10. func >>(lhs: Self, rhs: Self) -> Self
  11. func <<=(inout lhs: Self, rhs: Self)
  12. func >>=(inout lhs: 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. }