fix(xep): Fix issues with enhanced enums
This commit is contained in:
parent
1fdefacd52
commit
320f4a8d4c
@ -1,6 +1,7 @@
|
||||
## 0.3.2
|
||||
|
||||
- **BREAKING**: Remove `lastResource` from `XmppConnection`'s `connect` method. Instead, set the `StreamManagementNegotiator`'s `resource` attribute instead. Since the resource can only really be restored by stream management, this is no issue.
|
||||
- **BREAKING**: Changed order of parameters of `CryptographicHashManager.hashFromData`
|
||||
|
||||
## 0.3.1
|
||||
|
||||
|
@ -74,12 +74,6 @@ const forwardedXmlns = 'urn:xmpp:forward:0';
|
||||
// XEP-0300
|
||||
const hashXmlns = 'urn:xmpp:hashes:2';
|
||||
const hashFunctionNameBaseXmlns = 'urn:xmpp:hash-function-text-names';
|
||||
const hashSha256 = 'sha-256';
|
||||
const hashSha512 = 'sha-512';
|
||||
const hashSha3256 = 'sha3-256';
|
||||
const hashSha3512 = 'sha3-512';
|
||||
const hashBlake2b256 = 'blake2b-256';
|
||||
const hashBlake2b512 = 'blake2b-512';
|
||||
|
||||
// XEP-0308
|
||||
const lmcXmlns = 'urn:xmpp:message-correct:0';
|
||||
|
@ -4,6 +4,15 @@ import 'package:moxxmpp/src/managers/namespaces.dart';
|
||||
import 'package:moxxmpp/src/namespaces.dart';
|
||||
import 'package:moxxmpp/src/stringxml.dart';
|
||||
|
||||
/// Hash names
|
||||
const _hashSha256 = 'sha-256';
|
||||
const _hashSha512 = 'sha-512';
|
||||
const _hashSha3256 = 'sha3-256';
|
||||
const _hashSha3512 = 'sha3-512';
|
||||
const _hashBlake2b256 = 'blake2b-256';
|
||||
const _hashBlake2b512 = 'blake2b-512';
|
||||
|
||||
/// Helper method for building a <hash /> element according to XEP-0300.
|
||||
XMLNode constructHashElement(HashFunction hash, String value) {
|
||||
return XMLNode.xmlns(
|
||||
tag: 'hash',
|
||||
@ -37,17 +46,17 @@ enum HashFunction {
|
||||
/// - XEP-0300
|
||||
factory HashFunction.fromName(String name) {
|
||||
switch (name) {
|
||||
case hashSha256:
|
||||
case _hashSha256:
|
||||
return HashFunction.sha256;
|
||||
case hashSha512:
|
||||
case _hashSha512:
|
||||
return HashFunction.sha512;
|
||||
case hashSha3256:
|
||||
case _hashSha3256:
|
||||
return HashFunction.sha3_256;
|
||||
case hashSha3512:
|
||||
case _hashSha3512:
|
||||
return HashFunction.sha3_512;
|
||||
case hashBlake2b256:
|
||||
case _hashBlake2b256:
|
||||
return HashFunction.blake2b256;
|
||||
case hashBlake2b512:
|
||||
case _hashBlake2b512:
|
||||
return HashFunction.blake2b512;
|
||||
}
|
||||
|
||||
@ -58,17 +67,17 @@ enum HashFunction {
|
||||
String toName() {
|
||||
switch (this) {
|
||||
case HashFunction.sha256:
|
||||
return hashSha256;
|
||||
return _hashSha256;
|
||||
case HashFunction.sha512:
|
||||
return hashSha512;
|
||||
return _hashSha512;
|
||||
case HashFunction.sha3_256:
|
||||
return hashSha3512;
|
||||
return _hashSha3512;
|
||||
case HashFunction.sha3_512:
|
||||
return hashSha3512;
|
||||
return _hashSha3512;
|
||||
case HashFunction.blake2b256:
|
||||
return hashBlake2b256;
|
||||
return _hashBlake2b256;
|
||||
case HashFunction.blake2b512:
|
||||
return hashBlake2b512;
|
||||
return _hashBlake2b512;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -81,17 +90,19 @@ class CryptographicHashManager extends XmppManagerBase {
|
||||
|
||||
@override
|
||||
List<String> getDiscoFeatures() => [
|
||||
'$hashFunctionNameBaseXmlns:$hashSha256',
|
||||
'$hashFunctionNameBaseXmlns:$hashSha512',
|
||||
//'$hashFunctionNameBaseXmlns:$hashSha3256',
|
||||
//'$hashFunctionNameBaseXmlns:$hashSha3512',
|
||||
//'$hashFunctionNameBaseXmlns:$hashBlake2b256',
|
||||
'$hashFunctionNameBaseXmlns:$hashBlake2b512',
|
||||
'$hashFunctionNameBaseXmlns:$_hashSha256',
|
||||
'$hashFunctionNameBaseXmlns:$_hashSha512',
|
||||
//'$hashFunctionNameBaseXmlns:$_hashSha3256',
|
||||
//'$hashFunctionNameBaseXmlns:$_hashSha3512',
|
||||
//'$hashFunctionNameBaseXmlns:$_hashBlake2b256',
|
||||
'$hashFunctionNameBaseXmlns:$_hashBlake2b512',
|
||||
];
|
||||
|
||||
/// Compute the raw hash value of [data] using the algorithm specified by [function].
|
||||
/// If the function is not supported, an exception will be thrown.
|
||||
static Future<List<int>> hashFromData(
|
||||
List<int> data,
|
||||
HashFunction function,
|
||||
List<int> data,
|
||||
) async {
|
||||
// TODO(PapaTutuWawa): Implement the others as well
|
||||
HashAlgorithm algo;
|
||||
|
@ -217,11 +217,11 @@ class StickerPack {
|
||||
|
||||
// Calculate the hash
|
||||
final rawHash = await CryptographicHashManager.hashFromData(
|
||||
hashFunction,
|
||||
[
|
||||
...metaString,
|
||||
...stickersString,
|
||||
],
|
||||
hashFunction,
|
||||
);
|
||||
return base64.encode(rawHash).substring(0, 24);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user