diff --git a/analysis_options.yaml b/analysis_options.yaml index dee8927..b3a83ec 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -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 diff --git a/lib/src/bundle.dart b/lib/src/bundle.dart index c62a4e3..d43882e 100644 --- a/lib/src/bundle.dart +++ b/lib/src/bundle.dart @@ -1,6 +1,6 @@ import 'dart:convert'; import 'package:cryptography/cryptography.dart'; -import 'key.dart'; +import 'package:omemo_dart/src/key.dart'; class OmemoBundle { diff --git a/lib/src/key.dart b/lib/src/key.dart index e3f6db9..2cb85b1 100644 --- a/lib/src/key.dart +++ b/lib/src/key.dart @@ -9,7 +9,6 @@ const publicKeyLength = 32; class OmemoPublicKey { const OmemoPublicKey(this._pubkey); - final SimplePublicKey _pubkey; factory OmemoPublicKey.fromBytes(List 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 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) { diff --git a/lib/src/omemo_dart_base.dart b/lib/src/omemo_dart_base.dart deleted file mode 100644 index e8a6f15..0000000 --- a/lib/src/omemo_dart_base.dart +++ /dev/null @@ -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; -} diff --git a/lib/src/x3dh.dart b/lib/src/x3dh.dart index 34f7388..810231e 100644 --- a/lib/src/x3dh.dart +++ b/lib/src/x3dh.dart @@ -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> sig(OmemoKeyPair keyPair, List 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> sig(OmemoKeyPair keyPair, List 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> dh(OmemoKeyPair kp, OmemoPublicKey pk, int identityKey) async { var ckp = kp; var cpk = pk; @@ -60,8 +61,7 @@ Future> dh(OmemoKeyPair kp, OmemoPublicKey pk, int identityKey) async /// Derive a secret from the key material [km]. Future> kdf(List km) async { final f = List.filled(32, 0xFF); - final input = List.empty(growable: true); - input + final input = List.empty(growable: true) ..addAll(f) ..addAll(km); @@ -71,7 +71,7 @@ Future> kdf(List km) async { ); final output = await algorithm.deriveKey( secretKey: SecretKey(input), - // TODO: Fix + // TODO(PapaTutuWawa): Fix nonce: List.filled(32, 0x00), info: utf8.encode('OMEMO X3DH'), ); @@ -90,7 +90,7 @@ List concat(List> inputs) { } /// Alice builds a session with Bob using his bundle [bundle] and Alice's identity key -/// pair [ika]. +/// pair [ik]. Future x3dhFromBundle(OmemoBundle bundle, OmemoKeyPair ik) async { // Generate EK final ek = await OmemoKeyPair.generateNewPair(KeyPairType.x25519); diff --git a/pubspec.yaml b/pubspec.yaml index f67b758..be04049 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -13,3 +13,4 @@ dependencies: dev_dependencies: lints: ^2.0.0 test: ^1.21.0 + very_good_analysis: ^3.0.1 diff --git a/test/omemo_dart_test.dart b/test/x3dh_test.dart similarity index 94% rename from test/omemo_dart_test.dart rename to test/x3dh_test.dart index 84848b7..d2bd9a2 100644 --- a/test/omemo_dart_test.dart +++ b/test/x3dh_test.dart @@ -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(), {