Add pathDecryptionNonce as a param

This commit is contained in:
Vishnu Mohandas 2020-10-11 05:14:04 +05:30
parent a40355c249
commit 0ba60025f3
2 changed files with 26 additions and 3 deletions

View file

@ -17,7 +17,8 @@ class CollectionsDB {
static final columnKeyDecryptionNonce = 'key_decryption_nonce';
static final columnName = 'name';
static final columnType = 'type';
static final columnEncryptedPath = 'path';
static final columnEncryptedPath = 'encrypted_path';
static final columnPathDecryptionNonce = 'path_decryption_nonce';
static final columnCreationTime = 'creation_time';
CollectionsDB._privateConstructor();
@ -50,6 +51,7 @@ class CollectionsDB {
$columnName TEXT NOT NULL,
$columnType TEXT NOT NULL,
$columnEncryptedPath TEXT,
$columnPathDecryptionNonce TEXT,
$columnCreationTime TEXT NOT NULL,
)
''');
@ -65,6 +67,16 @@ class CollectionsDB {
return await batch.commit();
}
Future<List<Collection>> getAll() async {
final db = await instance.database;
final rows = await db.query(table);
final collections = List<Collection>();
for (final row in rows) {
collections.add(_convertToCollection(row));
}
return collections;
}
Future<int> getLastCollectionCreationTime() async {
final db = await instance.database;
final rows = await db.query(
@ -88,6 +100,7 @@ class CollectionsDB {
row[columnName] = collection.name;
row[columnType] = collection.type;
row[columnEncryptedPath] = collection.encryptedPath;
row[columnPathDecryptionNonce] = collection.pathDecryptionNonce;
row[columnCreationTime] = collection.creationTime;
return row;
}
@ -101,6 +114,7 @@ class CollectionsDB {
row[columnName],
row[columnType],
row[columnEncryptedPath],
row[columnPathDecryptionNonce],
int.parse(row[columnCreationTime]),
null,
);

View file

@ -10,6 +10,7 @@ class Collection {
final String name;
final CollectionType type;
final String encryptedPath;
final String pathDecryptionNonce;
final int creationTime;
final List<String> sharees;
@ -21,12 +22,14 @@ class Collection {
this.name,
this.type,
this.encryptedPath,
this.pathDecryptionNonce,
this.creationTime,
this.sharees,
);
static Collection emptyCollection() {
return Collection(null, null, null, null, null, null, null, null, List<String>());
return Collection(
null, null, null, null, null, null, null, null, null, List<String>());
}
Collection copyWith({
@ -37,6 +40,7 @@ class Collection {
String name,
CollectionType type,
String encryptedPath,
String pathDecryptionNonce,
int creationTime,
List<String> sharees,
}) {
@ -48,6 +52,7 @@ class Collection {
name ?? this.name,
type ?? this.type,
encryptedPath ?? this.encryptedPath,
encryptedPath ?? this.pathDecryptionNonce,
creationTime ?? this.creationTime,
sharees ?? this.sharees,
);
@ -63,6 +68,7 @@ class Collection {
'type': type.toString(),
'creationTime': creationTime,
'encryptedPath': encryptedPath,
'pathDecryptionNonce': pathDecryptionNonce,
'sharees': sharees,
};
}
@ -78,6 +84,7 @@ class Collection {
map['name'],
fromString(map['type']),
map['encryptedPath'],
map['pathDecryptionNonce'],
map['creationTime'],
map['sharees'] == null ? null : List<String>.from(map['sharees']),
);
@ -90,7 +97,7 @@ class Collection {
@override
String toString() {
return 'Collection(id: $id, ownerID: $ownerID, encryptedKey: $encryptedKey, keyDecryptionNonce: $keyDecryptionNonce, name: $name, type: $type, encryptedPath: $encryptedPath, creationTime: $creationTime, sharees: $sharees)';
return 'Collection(id: $id, ownerID: $ownerID, encryptedKey: $encryptedKey, keyDecryptionNonce: $keyDecryptionNonce, name: $name, type: $type, encryptedPath: $encryptedPath, pathDecryptionNonce: $pathDecryptionNonce, creationTime: $creationTime, sharees: $sharees)';
}
@override
@ -105,6 +112,7 @@ class Collection {
o.name == name &&
o.type == type &&
o.encryptedPath == encryptedPath &&
o.pathDecryptionNonce == pathDecryptionNonce &&
o.creationTime == creationTime &&
listEquals(o.sharees, sharees);
}
@ -118,6 +126,7 @@ class Collection {
name.hashCode ^
type.hashCode ^
encryptedPath.hashCode ^
pathDecryptionNonce.hashCode ^
creationTime.hashCode ^
sharees.hashCode;
}