Skip to content

Commit

Permalink
fix: Resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
sitaram-kalluri committed Oct 10, 2023
1 parent 0b1bedd commit 16db9f7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ class CommitLogKeyStore extends BaseCommitLogKeyStore {
}

/// Returns the latest committed sequence number with regex
Future<int?> lastCommittedSequenceNumberWithRegex(String regex) async {
Future<int?> lastCommittedSequenceNumberWithRegex(String regex,
{List<String>? enrolledNamespace}) async {
var lastCommittedEntry = (getBox() as Box).values.lastWhere(
(entry) => (_acceptKey(entry.atKey, regex)),
(entry) => (_acceptKey(entry.atKey, regex,
enrolledNamespace: enrolledNamespace)),
orElse: () => NullCommitEntry());
var lastCommittedSequenceNum =
(lastCommittedEntry != null) ? lastCommittedEntry.key : null;
Expand Down Expand Up @@ -177,19 +179,41 @@ class CommitLogKeyStore extends BaseCommitLogKeyStore {
}
}

bool _acceptKey(String atKey, String regex) {
return _isRegexMatches(atKey, regex) || _isSpecialKey(atKey);
bool _acceptKey(String atKey, String regex,
{List<String>? enrolledNamespace}) {
return _isNamespaceAuthorised(atKey, enrolledNamespace) &&
(_isRegexMatches(atKey, regex) || _isSpecialKey(atKey));
}

bool _isNamespaceAuthorised(String atKey, List<String>? enrolledNamespace) {
// This is work-around for : https://github.com/atsign-foundation/at_server/issues/1570
if (atKey == 'configkey') {
return true;
}
String? keyNamespace = AtKey.fromString(atKey).namespace;
// If enrolledNamespace is null or keyNamespace is null, fallback to
// existing behaviour - the key is authorized for the client to receive. So return true.
if (enrolledNamespace == null ||
enrolledNamespace.isEmpty ||
(keyNamespace == null || keyNamespace.isEmpty)) {
return true;
}
if (enrolledNamespace.contains('*') ||
enrolledNamespace.contains(keyNamespace)) {
return true;
}
return false;
}

bool _isRegexMatches(String atKey, String regex) {
return RegExp(regex).hasMatch(atKey);
}

bool _isSpecialKey(String atKey) {
return atKey.contains(AT_ENCRYPTION_SHARED_KEY) ||
return atKey.contains(AtConstants.atEncryptionSharedKey) ||
atKey.startsWith('public:') ||
atKey.contains(AT_PKAM_SIGNATURE) ||
atKey.contains(AT_SIGNING_PRIVATE_KEY);
atKey.contains(AtConstants.atPkamSignature) ||
atKey.contains(AtConstants.atSigningPrivateKey);
}

/// Returns the latest commitEntry of the key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ void main() async {
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {
await commitLogKeystore.getBox().add(CommitEntry(
'test_key_false_$i', CommitOp.UPDATE, DateTime.now()));
'test_key_false_$i.wavi@alice', CommitOp.UPDATE, DateTime.now()));
} else {
await commitLogKeystore.getBox().add(CommitEntry(
'test_key_false_$i', CommitOp.UPDATE, DateTime.now())
'test_key_false_$i.wavi@alice', CommitOp.UPDATE, DateTime.now())
..commitId = i);
}
}
Expand Down

0 comments on commit 16db9f7

Please sign in to comment.