Swiftgram/Postbox/KeychainTable.swift
2016-08-23 16:19:22 +03:00

27 lines
790 B
Swift

import Foundation
final class KeychainTable: Table {
override init(valueBox: ValueBox, tableId: Int32) {
super.init(valueBox: valueBox, tableId: tableId)
}
private func key(_ string: String) -> ValueBoxKey {
return ValueBoxKey(string)
}
func get(_ key: String) -> Data? {
if let value = self.valueBox.get(self.tableId, key: self.key(key)) {
return Data(bytes: value.memory.assumingMemoryBound(to: UInt8.self), count: value.length)
}
return nil
}
func set(_ key: String, value: Data) {
self.valueBox.set(self.tableId, key: self.key(key), value: MemoryBuffer(data: value))
}
func remove(_ key: String) {
self.valueBox.remove(self.tableId, key: self.key(key))
}
}