style: Lint using very_good_analysis

This commit is contained in:
2022-08-02 15:10:31 +02:00
parent d86e7f5963
commit 566cb1b0ec
7 changed files with 26 additions and 52 deletions

View File

@@ -1,6 +1,6 @@
import 'dart:convert';
import 'package:cryptography/cryptography.dart';
import 'key.dart';
import 'package:omemo_dart/src/key.dart';
class OmemoBundle {

View File

@@ -9,7 +9,6 @@ const publicKeyLength = 32;
class OmemoPublicKey {
const OmemoPublicKey(this._pubkey);
final SimplePublicKey _pubkey;
factory OmemoPublicKey.fromBytes(List<int> bytes, KeyPairType type) {
return OmemoPublicKey(
@@ -19,6 +18,8 @@ class OmemoPublicKey {
),
);
}
final SimplePublicKey _pubkey;
KeyPairType get type => _pubkey.type;
@@ -79,7 +80,7 @@ class OmemoKeyPair {
final OmemoPrivateKey sk;
static Future<OmemoKeyPair> generateNewPair(KeyPairType type) async {
assert(type == KeyPairType.ed25519 || type == KeyPairType.x25519);
assert(type == KeyPairType.ed25519 || type == KeyPairType.x25519, 'Keypair must be either Ed25519 or X25519');
SimpleKeyPair kp;
if (type == KeyPairType.ed25519) {

View File

@@ -1,6 +0,0 @@
// TODO: Put public facing types in this file.
/// Checks if you are awesome. Spoiler: you are.
class Awesome {
bool get isAwesome => true;
}

View File

@@ -1,8 +1,8 @@
import 'dart:convert';
import 'dart:math';
import 'package:cryptography/cryptography.dart';
import 'bundle.dart';
import 'key.dart';
import 'package:omemo_dart/src/bundle.dart';
import 'package:omemo_dart/src/key.dart';
/// The overarching assumption is that we use Ed25519 keys for the identity keys
@@ -27,7 +27,7 @@ class X3DHMessage {
/// Sign [message] using the keypair [keyPair]. Note that [keyPair] must be
/// a Ed25519 keypair.
Future<List<int>> sig(OmemoKeyPair keyPair, List<int> message) async {
assert(keyPair.type == KeyPairType.ed25519);
assert(keyPair.type == KeyPairType.ed25519, 'Signature keypair must be Ed25519');
final signature = await Ed25519().sign(
message,
keyPair: await keyPair.asKeyPair(),
@@ -36,9 +36,10 @@ Future<List<int>> sig(OmemoKeyPair keyPair, List<int> message) async {
return signature.bytes;
}
/// Performs X25519 with [pk1] and [pk2]. If [identityKey] is set, then
/// it indicates which of [pk1] ([identityKey] == 1) or [pk2] ([identityKey] == 2)
/// is the identity key.
/// Performs X25519 with [kp] and [pk]. If [identityKey] is set, then
/// it indicates which of [kp] ([identityKey] == 1) or [pk] ([identityKey] == 2)
/// is the identity key. This is needed since the identity key pair/public key is
/// an Ed25519 key, but we need them as X25519 keys for DH.
Future<List<int>> dh(OmemoKeyPair kp, OmemoPublicKey pk, int identityKey) async {
var ckp = kp;
var cpk = pk;
@@ -60,8 +61,7 @@ Future<List<int>> dh(OmemoKeyPair kp, OmemoPublicKey pk, int identityKey) async
/// Derive a secret from the key material [km].
Future<List<int>> kdf(List<int> km) async {
final f = List<int>.filled(32, 0xFF);
final input = List<int>.empty(growable: true);
input
final input = List<int>.empty(growable: true)
..addAll(f)
..addAll(km);
@@ -71,7 +71,7 @@ Future<List<int>> kdf(List<int> km) async {
);
final output = await algorithm.deriveKey(
secretKey: SecretKey(input),
// TODO: Fix
// TODO(PapaTutuWawa): Fix
nonce: List<int>.filled(32, 0x00),
info: utf8.encode('OMEMO X3DH'),
);
@@ -90,7 +90,7 @@ List<int> concat(List<List<int>> inputs) {
}
/// Alice builds a session with Bob using his bundle [bundle] and Alice's identity key
/// pair [ika].
/// pair [ik].
Future<X3DHResult> x3dhFromBundle(OmemoBundle bundle, OmemoKeyPair ik) async {
// Generate EK
final ek = await OmemoKeyPair.generateNewPair(KeyPairType.x25519);