Skip to content

Commit d54ab26

Browse files
committed
Formatting code with dartfmt.
1 parent 983df6e commit d54ab26

File tree

8 files changed

+120
-33
lines changed

8 files changed

+120
-33
lines changed

lib/src/auth/auth.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ abstract class PostgresAuthenticator {
1717
void onMessage(AuthenticationMessage message);
1818
}
1919

20-
PostgresAuthenticator createAuthenticator(PostgreSQLConnection connection, AuthenticationScheme authenticationScheme) {
20+
PostgresAuthenticator createAuthenticator(PostgreSQLConnection connection,
21+
AuthenticationScheme authenticationScheme) {
2122
switch (authenticationScheme) {
2223
case AuthenticationScheme.MD5:
2324
return MD5Authenticator(connection);
2425
case AuthenticationScheme.SCRAM_SHA_256:
25-
final credentials = UsernamePasswordCredential(username: connection.username, password: connection.password);
26-
return PostgresSaslAuthenticator(connection, ScramAuthenticator('SCRAM-SHA-256', sha256, credentials));
26+
final credentials = UsernamePasswordCredential(
27+
username: connection.username, password: connection.password);
28+
return PostgresSaslAuthenticator(
29+
connection, ScramAuthenticator('SCRAM-SHA-256', sha256, credentials));
2730
default:
2831
throw PostgreSQLException("Authenticator wasn't specified");
2932
}

lib/src/auth/md5_authenticator.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class MD5Authenticator extends PostgresAuthenticator {
1717
final reader = ByteDataReader()..add(message.bytes);
1818
final salt = reader.read(4, copy: true);
1919

20-
final authMessage = AuthMD5Message(connection.username!, connection.password!, salt);
20+
final authMessage =
21+
AuthMD5Message(connection.username!, connection.password!, salt);
2122

2223
connection.socket!.add(authMessage.asBytes());
2324
}
@@ -29,7 +30,8 @@ class AuthMD5Message extends ClientMessage {
2930
AuthMD5Message(String username, String password, List<int> saltBytes) {
3031
final passwordHash = md5.convert('$password$username'.codeUnits).toString();
3132
final saltString = String.fromCharCodes(saltBytes);
32-
final md5Hash = md5.convert('$passwordHash$saltString'.codeUnits).toString();
33+
final md5Hash =
34+
md5.convert('$passwordHash$saltString'.codeUnits).toString();
3335
_hashedAuthString = UTF8BackedString('md5$md5Hash');
3436
}
3537

lib/src/auth/sasl_authenticator.dart

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,34 @@ import 'auth.dart';
1313
class PostgresSaslAuthenticator extends PostgresAuthenticator {
1414
final SaslAuthenticator authenticator;
1515

16-
PostgresSaslAuthenticator(PostgreSQLConnection connection, this.authenticator) : super(connection);
16+
PostgresSaslAuthenticator(PostgreSQLConnection connection, this.authenticator)
17+
: super(connection);
1718

1819
@override
1920
void onMessage(AuthenticationMessage message) {
2021
ClientMessage msg;
2122
switch (message.type) {
2223
case AuthenticationMessage.KindSASL:
23-
final bytesToSend = authenticator.handleMessage(SaslMessageType.AuthenticationSASL, message.bytes);
24-
if (bytesToSend == null) throw PostgreSQLException('KindSASL: No bytes to send');
24+
final bytesToSend = authenticator.handleMessage(
25+
SaslMessageType.AuthenticationSASL, message.bytes);
26+
if (bytesToSend == null)
27+
throw PostgreSQLException('KindSASL: No bytes to send');
2528
msg = SaslClientFirstMessage(bytesToSend, authenticator.mechanism.name);
2629
break;
2730
case AuthenticationMessage.KindSASLContinue:
28-
final bytesToSend = authenticator.handleMessage(SaslMessageType.AuthenticationSASLContinue, message.bytes);
29-
if (bytesToSend == null) throw PostgreSQLException('KindSASLContinue: No bytes to send');
31+
final bytesToSend = authenticator.handleMessage(
32+
SaslMessageType.AuthenticationSASLContinue, message.bytes);
33+
if (bytesToSend == null)
34+
throw PostgreSQLException('KindSASLContinue: No bytes to send');
3035
msg = SaslClientLastMessage(bytesToSend);
3136
break;
3237
case AuthenticationMessage.KindSASLFinal:
33-
authenticator.handleMessage(SaslMessageType.AuthenticationSASLFinal, message.bytes);
38+
authenticator.handleMessage(
39+
SaslMessageType.AuthenticationSASLFinal, message.bytes);
3440
return;
3541
default:
36-
throw PostgreSQLException('Unsupported authentication type ${message.type}, closing connection.');
42+
throw PostgreSQLException(
43+
'Unsupported authentication type ${message.type}, closing connection.');
3744
}
3845
connection.socket!.add(msg.asBytes());
3946
}

lib/src/binary_codec.dart

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ class PostgresBinaryEncoder extends Converter<dynamic, Uint8List?> {
144144
0, value.toUtc().difference(DateTime.utc(2000)).inMicroseconds);
145145
return bd.buffer.asUint8List();
146146
}
147-
throw FormatException('Invalid type for parameter value. Expected: DateTime Got: ${value.runtimeType}');
147+
throw FormatException(
148+
'Invalid type for parameter value. Expected: DateTime Got: ${value.runtimeType}');
148149
}
149150

150151
case PostgreSQLDataType.numeric:
@@ -317,7 +318,8 @@ class PostgresBinaryEncoder extends Converter<dynamic, Uint8List?> {
317318
value = value.substring(1);
318319
}
319320
if (!_numericRegExp.hasMatch(value)) {
320-
throw FormatException('Invalid format for parameter value. Expected: String which matches "/^(\\d*)(\\.\\d*)?\$/" Got: ${value}');
321+
throw FormatException(
322+
'Invalid format for parameter value. Expected: String which matches "/^(\\d*)(\\.\\d*)?\$/" Got: ${value}');
321323
}
322324
final parts = value.split('.');
323325

@@ -338,10 +340,13 @@ class PostgresBinaryEncoder extends Converter<dynamic, Uint8List?> {
338340
// Weight of value 0 or '' is 0;
339341
weight = 0;
340342
} else {
341-
final leadingZeros = _leadingZerosRegExp.firstMatch(fractPart)?.group(0);
343+
final leadingZeros =
344+
_leadingZerosRegExp.firstMatch(fractPart)?.group(0);
342345
if (leadingZeros != null) {
343-
final leadingZerosWeight = leadingZeros.length ~/ 4; // Get count of leading zeros '0000'
344-
fractPart = fractPart.substring(leadingZerosWeight * 4); // Remove leading zeros '0000'
346+
final leadingZerosWeight =
347+
leadingZeros.length ~/ 4; // Get count of leading zeros '0000'
348+
fractPart = fractPart
349+
.substring(leadingZerosWeight * 4); // Remove leading zeros '0000'
345350
fractWeight -= leadingZerosWeight;
346351
weight = -(leadingZerosWeight + 1); // Ignore leading zeros in weight
347352
}
@@ -350,8 +355,12 @@ class PostgresBinaryEncoder extends Converter<dynamic, Uint8List?> {
350355
// If int fract has no weight, handle trailing zeros in int part.
351356
final trailingZeros = _trailingZerosRegExp.firstMatch(intPart)?.group(0);
352357
if (trailingZeros != null) {
353-
final trailingZerosWeight = trailingZeros.length ~/ 4; // Get count of trailing zeros '0000'
354-
intPart = intPart.substring(0, intPart.length - trailingZerosWeight * 4); // Remove leading zeros '0000'
358+
final trailingZerosWeight =
359+
trailingZeros.length ~/ 4; // Get count of trailing zeros '0000'
360+
intPart = intPart.substring(
361+
0,
362+
intPart.length -
363+
trailingZerosWeight * 4); // Remove leading zeros '0000'
355364
intWeight -= trailingZerosWeight;
356365
}
357366
}
@@ -543,9 +552,11 @@ class PostgresBinaryDecoder extends Converter<Uint8List, dynamic> {
543552
/// See implementation: https://github.com/charmander/pg-numeric/blob/0c310eeb11dc680dffb7747821e61d542831108b/index.js#L13
544553
static String _decodeNumeric(Uint8List value) {
545554
final reader = ByteDataReader()..add(value);
546-
final nDigits = reader.readInt16(); // non-zero digits, data buffer length = 2 * nDigits
555+
final nDigits =
556+
reader.readInt16(); // non-zero digits, data buffer length = 2 * nDigits
547557
var weight = reader.readInt16(); // weight of first digit
548-
final signByte = reader.readUint16(); // NUMERIC_POS, NEG, NAN, PINF, or NINF
558+
final signByte =
559+
reader.readUint16(); // NUMERIC_POS, NEG, NAN, PINF, or NINF
549560
final dScale = reader.readInt16(); // display scale
550561
if (signByte == 0xc000) return 'NaN';
551562
final sign = signByte == 0x4000 ? '-' : '';
@@ -573,7 +584,8 @@ class PostgresBinaryDecoder extends Converter<Uint8List, dynamic> {
573584
}
574585

575586
var result = '$sign${intPart.replaceAll(_leadingZerosRegExp, '')}';
576-
if (result.isEmpty) result = '0'; // Show at least 0, if no int value is given.
587+
if (result.isEmpty)
588+
result = '0'; // Show at least 0, if no int value is given.
577589
if (dScale > 0) {
578590
// Only add fractional digits, if dScale allows
579591
result += '.${fractPart.padRight(dScale, '0').substring(0, dScale)}';

lib/src/client_messages.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ abstract class ClientMessage {
1818
static const int ParseIdentifier = 80; //P
1919
static const int QueryIdentifier = 81; // Q
2020
static const int SyncIdentifier = 83; // S
21-
static const int PasswordIdentifier = 112; //p
21+
static const int PasswordIdentifier = 112; //p
2222

2323
void applyToBuffer(ByteDataWriter buffer);
2424

lib/src/connection_fsm.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ class _PostgreSQLConnectionStateSocketConnected
6767

6868
@override
6969
_PostgreSQLConnectionState onMessage(ServerMessage message) {
70-
7170
completer.completeError(PostgreSQLException(
7271
'Unsupported message "$message", closing connection.'));
7372

@@ -108,10 +107,12 @@ class _PostgreSQLConnectionStateAuthenticating
108107
case AuthenticationMessage.KindOK:
109108
return _PostgreSQLConnectionStateAuthenticated(completer);
110109
case AuthenticationMessage.KindMD5Password:
111-
_authenticator = createAuthenticator(connection!, AuthenticationScheme.MD5);
110+
_authenticator =
111+
createAuthenticator(connection!, AuthenticationScheme.MD5);
112112
continue authMsg;
113113
case AuthenticationMessage.KindSASL:
114-
_authenticator = createAuthenticator(connection!, AuthenticationScheme.SCRAM_SHA_256);
114+
_authenticator = createAuthenticator(
115+
connection!, AuthenticationScheme.SCRAM_SHA_256);
115116
continue authMsg;
116117
authMsg:
117118
case AuthenticationMessage.KindSASLContinue:

test/decode_test.dart

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ void main() {
9898
expect(row2[9], equals(DateTime.utc(2183, 11, 6)));
9999
expect(row2[10], equals(DateTime.utc(2183, 11, 6, 0, 0, 0, 111, 111)));
100100
expect(row2[11], equals(DateTime.utc(2183, 11, 6, 0, 0, 0, 999, 999)));
101-
expect(row2[12], equals('1000000000000000000000000000.0000000000000000000000000001'));
101+
expect(row2[12],
102+
equals('1000000000000000000000000000.0000000000000000000000000001'));
102103
expect(
103104
row2[13],
104105
equals([
@@ -179,7 +180,26 @@ void main() {
179180
test('Decode Numeric to String', () {
180181
final binaries = {
181182
'-123400000.20000': [0, 4, 0, 2, 64, 0, 0, 5, 0, 1, 9, 36, 0, 0, 7, 208],
182-
'-123400001.00002': [0, 5, 0, 2, 64, 0, 0, 5, 0, 1, 9, 36, 0, 1, 0, 0, 7, 208],
183+
'-123400001.00002': [
184+
0,
185+
5,
186+
0,
187+
2,
188+
64,
189+
0,
190+
0,
191+
5,
192+
0,
193+
1,
194+
9,
195+
36,
196+
0,
197+
1,
198+
0,
199+
0,
200+
7,
201+
208
202+
],
183203
'0.00001': [0, 1, 255, 254, 0, 0, 0, 5, 3, 232],
184204
'10000.000000000': [0, 1, 0, 1, 0, 0, 0, 9, 0, 1],
185205
'NaN': [0, 0, 0, 0, 192, 0, 0, 0],

test/encoding_test.dart

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,44 @@ void main() {
185185

186186
test('numeric', () async {
187187
final binaries = {
188-
'-123400000.20000': [0, 4, 0, 2, 64, 0, 0, 5, 0, 1, 9, 36, 0, 0, 7, 208],
189-
'-123400001.00002': [0, 5, 0, 2, 64, 0, 0, 5, 0, 1, 9, 36, 0, 1, 0, 0, 7, 208],
188+
'-123400000.20000': [
189+
0,
190+
4,
191+
0,
192+
2,
193+
64,
194+
0,
195+
0,
196+
5,
197+
0,
198+
1,
199+
9,
200+
36,
201+
0,
202+
0,
203+
7,
204+
208
205+
],
206+
'-123400001.00002': [
207+
0,
208+
5,
209+
0,
210+
2,
211+
64,
212+
0,
213+
0,
214+
5,
215+
0,
216+
1,
217+
9,
218+
36,
219+
0,
220+
1,
221+
0,
222+
0,
223+
7,
224+
208
225+
],
190226
'0.00001': [0, 1, 255, 254, 0, 0, 0, 5, 3, 232],
191227
'10000.000000000': [0, 1, 0, 1, 0, 0, 0, 9, 0, 1],
192228
'NaN': [0, 0, 0, 0, 192, 0, 0, 0],
@@ -201,9 +237,15 @@ void main() {
201237
expect(res, uint8List);
202238
});
203239

204-
await expectInverse('1000000000000000000000000000.0000000000000000000000000001', PostgreSQLDataType.numeric);
205-
await expectInverse('3141592653589793238462643383279502.1618033988749894848204586834365638', PostgreSQLDataType.numeric);
206-
await expectInverse('-3141592653589793238462643383279502.1618033988749894848204586834365638', PostgreSQLDataType.numeric);
240+
await expectInverse(
241+
'1000000000000000000000000000.0000000000000000000000000001',
242+
PostgreSQLDataType.numeric);
243+
await expectInverse(
244+
'3141592653589793238462643383279502.1618033988749894848204586834365638',
245+
PostgreSQLDataType.numeric);
246+
await expectInverse(
247+
'-3141592653589793238462643383279502.1618033988749894848204586834365638',
248+
PostgreSQLDataType.numeric);
207249
await expectInverse('0.0', PostgreSQLDataType.numeric);
208250
await expectInverse('0.1', PostgreSQLDataType.numeric);
209251
await expectInverse('0.0001', PostgreSQLDataType.numeric);

0 commit comments

Comments
 (0)