|
@@ -15,7 +15,7 @@
|
|
/// Keeps bytes in memory. Because this is class, bytes are not copied
|
|
/// Keeps bytes in memory. Because this is class, bytes are not copied
|
|
/// and memory area is locked as long as referenced, then unlocked on deinit
|
|
/// and memory area is locked as long as referenced, then unlocked on deinit
|
|
final class SecureBytes {
|
|
final class SecureBytes {
|
|
- private let bytes: Array<UInt8>
|
|
|
|
|
|
+ fileprivate let bytes: Array<UInt8>
|
|
let count: Int
|
|
let count: Int
|
|
|
|
|
|
init(bytes: Array<UInt8>) {
|
|
init(bytes: Array<UInt8>) {
|
|
@@ -31,8 +31,32 @@ final class SecureBytes {
|
|
munlock(pointer.baseAddress, pointer.count)
|
|
munlock(pointer.baseAddress, pointer.count)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+extension SecureBytes: Collection {
|
|
|
|
+ typealias Index = Int
|
|
|
|
+
|
|
|
|
+ var endIndex: Int {
|
|
|
|
+ return self.bytes.endIndex
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var startIndex: Int {
|
|
|
|
+ return self.bytes.startIndex
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ subscript(position: Index) -> UInt8 {
|
|
|
|
+ return self.bytes[position]
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ subscript(bounds: Range<Index>) -> ArraySlice<UInt8> {
|
|
|
|
+ return self.bytes[bounds]
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func formIndex(after i: inout Int) {
|
|
|
|
+ self.bytes.formIndex(after: &i)
|
|
|
|
+ }
|
|
|
|
|
|
- subscript(index: Int) -> UInt8 {
|
|
|
|
- return self.bytes[index]
|
|
|
|
|
|
+ func index(after i: Int) -> Int {
|
|
|
|
+ return self.bytes.index(after: i)
|
|
}
|
|
}
|
|
}
|
|
}
|