swift-sodium/Sodium/Bytes.swift

22 lines
455 B
Swift
Raw Permalink Normal View History

import Foundation
public typealias Bytes = Array<UInt8>
extension Array where Element == UInt8 {
init (count bytes: Int) {
self.init(repeating: 0, count: bytes)
}
public var utf8String: String? {
return String(data: Data(self), encoding: .utf8)
}
}
extension ArraySlice where Element == UInt8 {
var bytes: Bytes { return Bytes(self) }
}
public extension String {
var bytes: Bytes { return Bytes(self.utf8) }
}