style: Lint using very_good_analysis
This commit is contained in:
parent
d86e7f5963
commit
566cb1b0ec
@ -1,30 +1,8 @@
|
|||||||
# This file configures the static analysis results for your project (errors,
|
include: package:very_good_analysis/analysis_options.yaml
|
||||||
# warnings, and lints).
|
linter:
|
||||||
#
|
rules:
|
||||||
# This enables the 'recommended' set of lints from `package:lints`.
|
public_member_api_docs: false
|
||||||
# This set helps identify many issues that may lead to problems when running
|
lines_longer_than_80_chars: false
|
||||||
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
|
use_setters_to_change_properties: false
|
||||||
# style and format.
|
avoid_positional_boolean_parameters: false
|
||||||
#
|
avoid_bool_literals_in_conditional_expressions: false
|
||||||
# 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
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:cryptography/cryptography.dart';
|
import 'package:cryptography/cryptography.dart';
|
||||||
import 'key.dart';
|
import 'package:omemo_dart/src/key.dart';
|
||||||
|
|
||||||
class OmemoBundle {
|
class OmemoBundle {
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ const publicKeyLength = 32;
|
|||||||
class OmemoPublicKey {
|
class OmemoPublicKey {
|
||||||
|
|
||||||
const OmemoPublicKey(this._pubkey);
|
const OmemoPublicKey(this._pubkey);
|
||||||
final SimplePublicKey _pubkey;
|
|
||||||
|
|
||||||
factory OmemoPublicKey.fromBytes(List<int> bytes, KeyPairType type) {
|
factory OmemoPublicKey.fromBytes(List<int> bytes, KeyPairType type) {
|
||||||
return OmemoPublicKey(
|
return OmemoPublicKey(
|
||||||
@ -19,6 +18,8 @@ class OmemoPublicKey {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final SimplePublicKey _pubkey;
|
||||||
|
|
||||||
KeyPairType get type => _pubkey.type;
|
KeyPairType get type => _pubkey.type;
|
||||||
|
|
||||||
@ -79,7 +80,7 @@ class OmemoKeyPair {
|
|||||||
final OmemoPrivateKey sk;
|
final OmemoPrivateKey sk;
|
||||||
|
|
||||||
static Future<OmemoKeyPair> generateNewPair(KeyPairType type) async {
|
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;
|
SimpleKeyPair kp;
|
||||||
if (type == KeyPairType.ed25519) {
|
if (type == KeyPairType.ed25519) {
|
||||||
|
@ -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;
|
|
||||||
}
|
|
@ -1,8 +1,8 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
import 'package:cryptography/cryptography.dart';
|
import 'package:cryptography/cryptography.dart';
|
||||||
import 'bundle.dart';
|
import 'package:omemo_dart/src/bundle.dart';
|
||||||
import 'key.dart';
|
import 'package:omemo_dart/src/key.dart';
|
||||||
|
|
||||||
/// The overarching assumption is that we use Ed25519 keys for the identity keys
|
/// 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
|
/// Sign [message] using the keypair [keyPair]. Note that [keyPair] must be
|
||||||
/// a Ed25519 keypair.
|
/// a Ed25519 keypair.
|
||||||
Future<List<int>> sig(OmemoKeyPair keyPair, List<int> message) async {
|
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(
|
final signature = await Ed25519().sign(
|
||||||
message,
|
message,
|
||||||
keyPair: await keyPair.asKeyPair(),
|
keyPair: await keyPair.asKeyPair(),
|
||||||
@ -36,9 +36,10 @@ Future<List<int>> sig(OmemoKeyPair keyPair, List<int> message) async {
|
|||||||
return signature.bytes;
|
return signature.bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Performs X25519 with [pk1] and [pk2]. If [identityKey] is set, then
|
/// Performs X25519 with [kp] and [pk]. If [identityKey] is set, then
|
||||||
/// it indicates which of [pk1] ([identityKey] == 1) or [pk2] ([identityKey] == 2)
|
/// it indicates which of [kp] ([identityKey] == 1) or [pk] ([identityKey] == 2)
|
||||||
/// is the identity key.
|
/// 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 {
|
Future<List<int>> dh(OmemoKeyPair kp, OmemoPublicKey pk, int identityKey) async {
|
||||||
var ckp = kp;
|
var ckp = kp;
|
||||||
var cpk = pk;
|
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].
|
/// Derive a secret from the key material [km].
|
||||||
Future<List<int>> kdf(List<int> km) async {
|
Future<List<int>> kdf(List<int> km) async {
|
||||||
final f = List<int>.filled(32, 0xFF);
|
final f = List<int>.filled(32, 0xFF);
|
||||||
final input = List<int>.empty(growable: true);
|
final input = List<int>.empty(growable: true)
|
||||||
input
|
|
||||||
..addAll(f)
|
..addAll(f)
|
||||||
..addAll(km);
|
..addAll(km);
|
||||||
|
|
||||||
@ -71,7 +71,7 @@ Future<List<int>> kdf(List<int> km) async {
|
|||||||
);
|
);
|
||||||
final output = await algorithm.deriveKey(
|
final output = await algorithm.deriveKey(
|
||||||
secretKey: SecretKey(input),
|
secretKey: SecretKey(input),
|
||||||
// TODO: Fix
|
// TODO(PapaTutuWawa): Fix
|
||||||
nonce: List<int>.filled(32, 0x00),
|
nonce: List<int>.filled(32, 0x00),
|
||||||
info: utf8.encode('OMEMO X3DH'),
|
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
|
/// 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 {
|
Future<X3DHResult> x3dhFromBundle(OmemoBundle bundle, OmemoKeyPair ik) async {
|
||||||
// Generate EK
|
// Generate EK
|
||||||
final ek = await OmemoKeyPair.generateNewPair(KeyPairType.x25519);
|
final ek = await OmemoKeyPair.generateNewPair(KeyPairType.x25519);
|
||||||
|
@ -13,3 +13,4 @@ dependencies:
|
|||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
lints: ^2.0.0
|
lints: ^2.0.0
|
||||||
test: ^1.21.0
|
test: ^1.21.0
|
||||||
|
very_good_analysis: ^3.0.1
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import 'package:cryptography/cryptography.dart';
|
import 'package:cryptography/cryptography.dart';
|
||||||
import 'package:test/test.dart';
|
|
||||||
import 'package:omemo_dart/omemo_dart.dart';
|
import 'package:omemo_dart/omemo_dart.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test("X3DH", () async {
|
test('X3DH', () async {
|
||||||
// Generate keys
|
// Generate keys
|
||||||
final ikAlice = await OmemoKeyPair.generateNewPair(KeyPairType.ed25519);
|
final ikAlice = await OmemoKeyPair.generateNewPair(KeyPairType.ed25519);
|
||||||
final ikBob = await OmemoKeyPair.generateNewPair(KeyPairType.ed25519);
|
final ikBob = await OmemoKeyPair.generateNewPair(KeyPairType.ed25519);
|
||||||
@ -13,7 +13,7 @@ void main() {
|
|||||||
'1',
|
'1',
|
||||||
await spkBob.pk.asBase64(),
|
await spkBob.pk.asBase64(),
|
||||||
'3',
|
'3',
|
||||||
// TODO(PapaTutuWawa):
|
// TODO(PapaTutuWawa): Do
|
||||||
'n/a',
|
'n/a',
|
||||||
await ikBob.pk.asBase64(),
|
await ikBob.pk.asBase64(),
|
||||||
{
|
{
|
Loading…
Reference in New Issue
Block a user