style: Lint using very_good_analysis

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

View File

@ -1,30 +1,8 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.
include: package:lints/recommended.yaml
# Uncomment the following section to specify additional rules.
# linter:
# rules:
# - camel_case_types
# analyzer:
# exclude:
# - path/to/excluded/files/**
# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints
# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options
include: package:very_good_analysis/analysis_options.yaml
linter:
rules:
public_member_api_docs: false
lines_longer_than_80_chars: false
use_setters_to_change_properties: false
avoid_positional_boolean_parameters: false
avoid_bool_literals_in_conditional_expressions: false

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);

View File

@ -13,3 +13,4 @@ dependencies:
dev_dependencies:
lints: ^2.0.0
test: ^1.21.0
very_good_analysis: ^3.0.1

View File

@ -1,9 +1,9 @@
import 'package:cryptography/cryptography.dart';
import 'package:test/test.dart';
import 'package:omemo_dart/omemo_dart.dart';
import 'package:test/test.dart';
void main() {
test("X3DH", () async {
test('X3DH', () async {
// Generate keys
final ikAlice = await OmemoKeyPair.generateNewPair(KeyPairType.ed25519);
final ikBob = await OmemoKeyPair.generateNewPair(KeyPairType.ed25519);
@ -13,7 +13,7 @@ void main() {
'1',
await spkBob.pk.asBase64(),
'3',
// TODO(PapaTutuWawa):
// TODO(PapaTutuWawa): Do
'n/a',
await ikBob.pk.asBase64(),
{