Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: at_persistence _impl changes for replacing md5 #1775

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 131 additions & 45 deletions packages/at_persistence_secondary_server/lib/src/model/at_meta_data.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:at_commons/at_commons.dart' as at_commons;
import 'package:at_commons/at_commons.dart';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why imported twice?

import 'package:at_persistence_secondary_server/at_persistence_secondary_server.dart';
import 'package:at_persistence_secondary_server/src/utils/type_adapter_util.dart';
Expand Down Expand Up @@ -77,15 +78,18 @@ class AtMetaData extends HiveObject {
@HiveField(23)
String? skeEncAlgo;

@HiveField(24)
PublicKeyHash? publicKeyHash;

@override
String toString() {
return toJson().toString();
}

AtMetaData();

Metadata toCommonsMetadata() {
return Metadata()
at_commons.Metadata toCommonsMetadata() {
return at_commons.Metadata()
..ttl = ttl
..ttb = ttb
..ttr = ttr
Expand All @@ -95,6 +99,11 @@ class AtMetaData extends HiveObject {
..dataSignature = dataSignature
..sharedKeyEnc = sharedKeyEnc
..pubKeyCS = pubKeyCS
//#TODO handle null objects
..pubKeyHash = (at_commons.PublicKeyHash()
..hash = publicKeyHash?.hash
..publicKeyHashingAlgo =
PublicKeyHashingAlgo.values.byName(publicKeyHash!.hashingAlgo!))
..encoding = encoding
..encKeyName = encKeyName
..encAlgo = encAlgo
Expand All @@ -103,7 +112,7 @@ class AtMetaData extends HiveObject {
..skeEncAlgo = skeEncAlgo;
}

factory AtMetaData.fromCommonsMetadata(Metadata metadata) {
factory AtMetaData.fromCommonsMetadata(at_commons.Metadata metadata) {
var atMetadata = AtMetaData();
atMetadata
..ttl = metadata.ttl
Expand All @@ -115,6 +124,9 @@ class AtMetaData extends HiveObject {
..dataSignature = metadata.dataSignature
..sharedKeyEnc = metadata.sharedKeyEnc
..pubKeyCS = metadata.pubKeyCS
..publicKeyHash = (PublicKeyHash()
..hash = metadata.pubKeyHash!.hash
..hashingAlgo = metadata.pubKeyHash!.publicKeyHashingAlgo!.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to handle nulls here also

..encoding = metadata.encoding
..encKeyName = metadata.encKeyName
..encAlgo = metadata.encAlgo
Expand All @@ -136,21 +148,24 @@ class AtMetaData extends HiveObject {
map['refreshAt'] = refreshAt?.toUtc().toString();
map['status'] = status;
map['version'] = version;
map[AtConstants.ttl] = ttl;
map[AtConstants.ttb] = ttb;
map[AtConstants.ttr] = ttr;
map[AtConstants.ccd] = isCascade;
map[AtConstants.isBinary] = isBinary;
map[AtConstants.isEncrypted] = isEncrypted;
map[AtConstants.publicDataSignature] = dataSignature;
map[AtConstants.sharedKeyEncrypted] = sharedKeyEnc;
map[AtConstants.sharedWithPublicKeyCheckSum] = pubKeyCS;
map[AtConstants.encoding] = encoding;
map[AtConstants.encryptingKeyName] = encKeyName;
map[AtConstants.encryptingAlgo] = encAlgo;
map[AtConstants.ivOrNonce] = ivNonce;
map[AtConstants.sharedKeyEncryptedEncryptingKeyName] = skeEncKeyName;
map[AtConstants.sharedKeyEncryptedEncryptingAlgo] = skeEncAlgo;
map[at_commons.AtConstants.ttl] = ttl;
map[at_commons.AtConstants.ttb] = ttb;
map[at_commons.AtConstants.ttr] = ttr;
map[at_commons.AtConstants.ccd] = isCascade;
map[at_commons.AtConstants.isBinary] = isBinary;
map[at_commons.AtConstants.isEncrypted] = isEncrypted;
map[at_commons.AtConstants.publicDataSignature] = dataSignature;
map[at_commons.AtConstants.sharedKeyEncrypted] = sharedKeyEnc;
map[at_commons.AtConstants.sharedWithPublicKeyCheckSum] = pubKeyCS;
map[at_commons.AtConstants.encoding] = encoding;
map[at_commons.AtConstants.encryptingKeyName] = encKeyName;
map[at_commons.AtConstants.encryptingAlgo] = encAlgo;
map[at_commons.AtConstants.ivOrNonce] = ivNonce;
map[at_commons.AtConstants.sharedKeyEncryptedEncryptingKeyName] =
skeEncKeyName;
map[at_commons.AtConstants.sharedKeyEncryptedEncryptingAlgo] = skeEncAlgo;
map[at_commons.AtConstants.sharedWithPublicKeyHash] =
publicKeyHash?.toJson();
return map;
}

Expand Down Expand Up @@ -178,34 +193,35 @@ class AtMetaData extends HiveObject {
: (json['version'] == null)
? 0
: json['version'];
ttl = (json[AtConstants.ttl] is String)
? int.parse(json[AtConstants.ttl])
: (json[AtConstants.ttl] == null)
ttl = (json[at_commons.AtConstants.ttl] is String)
? int.parse(json[at_commons.AtConstants.ttl])
: (json[at_commons.AtConstants.ttl] == null)
? null
: json[AtConstants.ttl];
ttb = (json[AtConstants.ttb] is String)
? int.parse(json[AtConstants.ttb])
: (json[AtConstants.ttb] == null)
: json[at_commons.AtConstants.ttl];
ttb = (json[at_commons.AtConstants.ttb] is String)
? int.parse(json[at_commons.AtConstants.ttb])
: (json[at_commons.AtConstants.ttb] == null)
? null
: json[AtConstants.ttb];
ttr = (json[AtConstants.ttr] is String)
? int.parse(json[AtConstants.ttr])
: (json[AtConstants.ttr] == null)
: json[at_commons.AtConstants.ttb];
ttr = (json[at_commons.AtConstants.ttr] is String)
? int.parse(json[at_commons.AtConstants.ttr])
: (json[at_commons.AtConstants.ttr] == null)
? null
: json[AtConstants.ttr];
isCascade = json[AtConstants.ccd];
isBinary = json[AtConstants.isBinary];
isEncrypted = json[AtConstants.isEncrypted];
dataSignature = json[AtConstants.publicDataSignature];
sharedKeyEnc = json[AtConstants.sharedKeyEncrypted];
pubKeyCS = json[AtConstants.sharedWithPublicKeyCheckSum];
encoding = json[AtConstants.encoding];
encKeyName = json[AtConstants.encryptingKeyName];
encAlgo = json[AtConstants.encryptingAlgo];
ivNonce = json[AtConstants.ivOrNonce];
skeEncKeyName = json[AtConstants.sharedKeyEncryptedEncryptingKeyName];
skeEncAlgo = json[AtConstants.sharedKeyEncryptedEncryptingAlgo];

: json[at_commons.AtConstants.ttr];
isCascade = json[at_commons.AtConstants.ccd];
isBinary = json[at_commons.AtConstants.isBinary];
isEncrypted = json[at_commons.AtConstants.isEncrypted];
dataSignature = json[at_commons.AtConstants.publicDataSignature];
sharedKeyEnc = json[at_commons.AtConstants.sharedKeyEncrypted];
pubKeyCS = json[at_commons.AtConstants.sharedWithPublicKeyCheckSum];
encoding = json[at_commons.AtConstants.encoding];
encKeyName = json[at_commons.AtConstants.encryptingKeyName];
encAlgo = json[at_commons.AtConstants.encryptingAlgo];
ivNonce = json[at_commons.AtConstants.ivOrNonce];
skeEncKeyName =
json[at_commons.AtConstants.sharedKeyEncryptedEncryptingKeyName];
skeEncAlgo = json[at_commons.AtConstants.sharedKeyEncryptedEncryptingAlgo];
publicKeyHash = json[at_commons.AtConstants.sharedWithPublicKeyHash];
return this;
}

Expand All @@ -232,6 +248,7 @@ class AtMetaData extends HiveObject {
dataSignature == other.dataSignature &&
sharedKeyEnc == other.sharedKeyEnc &&
pubKeyCS == other.pubKeyCS &&
publicKeyHash == other.publicKeyHash &&
encoding == other.encoding &&
encKeyName == other.encKeyName &&
encAlgo == other.encAlgo &&
Expand Down Expand Up @@ -259,6 +276,7 @@ class AtMetaData extends HiveObject {
dataSignature.hashCode ^
sharedKeyEnc.hashCode ^
pubKeyCS.hashCode ^
publicKeyHash.hashCode ^
encoding.hashCode ^
encKeyName.hashCode ^
encAlgo.hashCode ^
Expand Down Expand Up @@ -301,7 +319,8 @@ class AtMetaDataAdapter extends TypeAdapter<AtMetaData> {
..encAlgo = fields[20]
..ivNonce = fields[21]
..skeEncKeyName = fields[22]
..skeEncAlgo = fields[23];
..skeEncAlgo = fields[23]
..publicKeyHash = fields[24];
}

@override
Expand Down Expand Up @@ -355,6 +374,73 @@ class AtMetaDataAdapter extends TypeAdapter<AtMetaData> {
..writeByte(22)
..write(obj.skeEncKeyName)
..writeByte(23)
..write(obj.skeEncAlgo);
..write(obj.skeEncAlgo)
..writeByte(24)
..write(obj.publicKeyHash);
}
}

@HiveType(typeId: 11)
class PublicKeyHash extends HiveObject {
String? hash;
String? hashingAlgo;
PublicKeyHash();
Map toJson() {
Map map = {};
map['hash'] = hash;
map['hashingAlgo'] = hashingAlgo;
return map;
}

factory PublicKeyHash.fromJson(Map json) {
return PublicKeyHash().fromJson(json);
}

PublicKeyHash fromJson(Map json) {
hash = json['hash'];
hashingAlgo = json['hashingAlgo'];
return this;
}

@override
String toString() {
return toJson().toString();
}

@override
bool operator ==(Object other) =>
identical(this, other) ||
other is PublicKeyHash &&
runtimeType == other.runtimeType &&
hash == other.hash &&
hashingAlgo == other.hashingAlgo;

@override
int get hashCode => hash.hashCode ^ hashingAlgo.hashCode;
}

class PublicKeyHashAdapter extends TypeAdapter<PublicKeyHash> {
@override
final int typeId = typeAdapterMap['PublicKeyHashAdapter'];

@override
PublicKeyHash read(BinaryReader reader) {
var numOfFields = reader.readByte();
var fields = <int, dynamic>{
for (var i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
};
return PublicKeyHash()
..hash = fields[0] as String?
..hashingAlgo = fields[1] as String?;
}

@override
void write(BinaryWriter writer, PublicKeyHash obj) {
writer
..writeByte(2)
..writeByte(0)
..write(obj.hash)
..writeByte(1)
..write(obj.hashingAlgo);
}
}
7 changes: 6 additions & 1 deletion packages/at_persistence_secondary_server/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ dependencies:
at_persistence_spec: ^2.0.14
meta: ^1.8.0

dev_dependencies:
dependency_overrides:
at_commons:
git:
url: https://github.com/atsign-foundation/at_libraries
path: packages/at_commons
ref: at_commons_replace_md5
lints: ^2.0.1
test: ^1.22.1
coverage: ^1.6.1
Expand Down
Loading