-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #214 from atsign-foundation/atkey_types
feat: Atkey add getKeyType
- Loading branch information
Showing
7 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ enum KeyType { | |
privateKey, | ||
cachedPublicKey, | ||
cachedSharedKey, | ||
reservedKey, | ||
invalidKey | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import 'package:at_commons/at_commons.dart'; | ||
import 'package:at_commons/src/keystore/key_type.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group('A group of tests to verify key types', () { | ||
test('Test to verify a public key type with namespace', () { | ||
var keyType = AtKey.getKeyType('public:phone.wavi@bob'); | ||
expect(keyType, equals(KeyType.publicKey)); | ||
}); | ||
|
||
test('Test to verify a cached public key type with namespace', () { | ||
var keyType = AtKey.getKeyType('cached:public:phone.buzz@bob'); | ||
expect(keyType, equals(KeyType.cachedPublicKey)); | ||
}); | ||
|
||
test('Test to verify a shared key type with namespace', () { | ||
var keyType = AtKey.getKeyType('@alice:phone.wavi@bob'); | ||
expect(keyType, equals(KeyType.sharedKey)); | ||
}); | ||
|
||
test('Test to verify a cached shared key type with namespace', () { | ||
var keyType = AtKey.getKeyType('cached:@alice:phone.buzz@bob'); | ||
expect(keyType, equals(KeyType.cachedSharedKey)); | ||
}); | ||
|
||
test('Test to verify self key type with namespace', () { | ||
var keyType = AtKey.getKeyType('@bob:phone.buzz@bob'); | ||
expect(keyType, equals(KeyType.selfKey)); | ||
}); | ||
}); | ||
group('A group of tests to check invalid key types', () { | ||
test('Test public key type without namespace', () { | ||
var keyType = | ||
AtKey.getKeyType('public:phone@bob', enforceNameSpace: true); | ||
expect(keyType, equals(KeyType.invalidKey)); | ||
}); | ||
|
||
test('Test cached public key type without namespace', () { | ||
var keyType = | ||
AtKey.getKeyType('cached:public:phone@bob', enforceNameSpace: true); | ||
expect(keyType, equals(KeyType.invalidKey)); | ||
}); | ||
|
||
test('Test shared key type without namespace', () { | ||
var keyType = | ||
AtKey.getKeyType('@alice:phone@bob', enforceNameSpace: true); | ||
expect(keyType, equals(KeyType.invalidKey)); | ||
}); | ||
|
||
test('Test cached shared key type without namespace', () { | ||
var keyType = | ||
AtKey.getKeyType('cached:@alice:phone@bob', enforceNameSpace: true); | ||
expect(keyType, equals(KeyType.invalidKey)); | ||
}); | ||
|
||
test('Test self key type without sharedWith atsign and without namespace', | ||
() { | ||
var keyType = AtKey.getKeyType('phone@bob', enforceNameSpace: true); | ||
expect(keyType, equals(KeyType.invalidKey)); | ||
}); | ||
test('Test self key type with atsign and without namespace', () { | ||
var keyType = AtKey.getKeyType('@bob:phone@bob', enforceNameSpace: true); | ||
expect(keyType, equals(KeyType.invalidKey)); | ||
}); | ||
}); | ||
|
||
group('A group of tests to check reserved key types', () { | ||
test('Test reserved key type for shared_key', () { | ||
var keyType = AtKey.getKeyType('@bob:shared_key@alice'); | ||
expect(keyType, equals(KeyType.reservedKey)); | ||
}); | ||
|
||
test('Test reserved key type for encryption publickey', () { | ||
var keyType = AtKey.getKeyType('public:publickey@alice'); | ||
expect(keyType, equals(KeyType.reservedKey)); | ||
}); | ||
|
||
test('Test reserved key type for public session key', () { | ||
var keyType = AtKey.getKeyType( | ||
'public:_a29464d0-1f2d-4216-b903-031963bc4ab3@alice'); | ||
expect(keyType, equals(KeyType.reservedKey)); | ||
}); | ||
|
||
test('Test reserved key type for latest notification id', () { | ||
var keyType = AtKey.getKeyType('_latestNotificationIdv2'); | ||
expect(keyType, equals(KeyType.reservedKey)); | ||
}); | ||
|
||
test('Test reserved key type for signing public key', () { | ||
var keyType = AtKey.getKeyType('public:signing_publickey@colin'); | ||
expect(keyType, equals(KeyType.reservedKey)); | ||
}); | ||
}); | ||
} |