Skip to content

Conversation

@inuEbisu
Copy link
Contributor

No description provided.

@Harry-Chen Harry-Chen requested a review from Copilot August 16, 2025 08:35
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements custom toString() methods for data classes across the FIDO2 library to improve debugging and logging capabilities. The implementation provides structured, multi-line string representations that include all relevant fields with proper formatting for binary data.

  • Adds consistent toString() implementations using StringBuffer for formatted output
  • Includes hex encoding for binary data fields using the convert package
  • Handles optional fields with conditional formatting

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
lib/src/ctap2/requests/make_credential.dart Adds toString() methods for MakeCredentialRequest and MakeCredentialResponse classes
lib/src/ctap2/requests/get_assertion.dart Adds toString() methods for GetAssertionRequest and GetAssertionResponse classes
lib/src/ctap2/requests/credential_mgmt.dart Adds toString() methods for CredentialManagementRequest and CredentialManagementResponse classes
lib/src/ctap2/requests/client_pin.dart Adds toString() methods for ClientPinRequest and ClientPinResponse classes
lib/src/ctap2/pin.dart Adds toString() method for EncapsulateResult class and updates imports
lib/src/ctap2/entities/credential_entities.dart Updates toString() methods for credential entity classes with improved formatting
lib/src/ctap2/entities/authenticator_info.dart Adds comprehensive toString() method for AuthenticatorInfo class
lib/src/ctap2/credmgmt.dart Adds toString() methods for credential management helper classes
lib/src/ctap.dart Adds toString() methods for CtapResponse and updates CtapError toString()
lib/src/cose.dart Adds toString() methods for COSE key classes with hex-encoded coordinate display

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

final buffer = StringBuffer();
buffer.writeln('EncapsulateResult(');
buffer.writeln(' coseKey: $coseKey,');
buffer.writeln(' sharedSecret: ${hex.encode(sharedSecret)}');
Copy link

Copilot AI Aug 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma after the last field. For consistency with other toString() implementations in this PR, add a comma after 'sharedSecret'.

Suggested change
buffer.writeln(' sharedSecret: ${hex.encode(sharedSecret)}');
buffer.writeln(' sharedSecret: ${hex.encode(sharedSecret)},');

Copilot uses AI. Check for mistakes.
return 'PublicKeyCredentialRpEntity(id: $id)';
final buffer = StringBuffer();
buffer.writeln('PublicKeyCredentialRpEntity(');
buffer.writeln(' id: $id');
Copy link

Copilot AI Aug 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma after the last field. For consistency with other toString() implementations in this PR, add a comma after 'id'.

Suggested change
buffer.writeln(' id: $id');
buffer.writeln(' id: $id,');

Copilot uses AI. Check for mistakes.
buffer.writeln('PublicKeyCredentialUserEntity(');
buffer.writeln(' id: ${hex.encode(id)},');
buffer.writeln(' name: $name,');
buffer.writeln(' displayName: $displayName');
Copy link

Copilot AI Aug 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma after the last field. For consistency with other toString() implementations in this PR, add a comma after 'displayName'.

Suggested change
buffer.writeln(' displayName: $displayName');
buffer.writeln(' displayName: $displayName,');

Copilot uses AI. Check for mistakes.
buffer.writeln('PublicKeyCredentialDescriptor(');
buffer.writeln(' type: $type,');
buffer.writeln(' id: ${hex.encode(id)},');
if (transports != null) buffer.writeln(' transports: $transports,');
Copy link

Copilot AI Aug 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'id' field has a trailing comma but should not have one since it's always the last field before the conditional 'transports' field. Remove the comma or restructure to maintain consistency.

Suggested change
if (transports != null) buffer.writeln(' transports: $transports,');
if (transports != null) {
buffer.writeln(' id: ${hex.encode(id)},');
buffer.writeln(' transports: $transports,');
} else {
buffer.writeln(' id: ${hex.encode(id)}');
}

Copilot uses AI. Check for mistakes.
buffer.writeln(
' existingResidentCredentialsCount: $existingResidentCredentialsCount,');
buffer.writeln(
' maxPossibleRemainingResidentCredentialsCount: $maxPossibleRemainingResidentCredentialsCount');
Copy link

Copilot AI Aug 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma after the last field. For consistency with other toString() implementations in this PR, add a comma after 'maxPossibleRemainingResidentCredentialsCount'.

Suggested change
' maxPossibleRemainingResidentCredentialsCount: $maxPossibleRemainingResidentCredentialsCount');
' maxPossibleRemainingResidentCredentialsCount: $maxPossibleRemainingResidentCredentialsCount,');

Copilot uses AI. Check for mistakes.
final buffer = StringBuffer();
buffer.writeln('CtapError(');
buffer.writeln(' status: ${status.value},');
buffer.writeln(' name: ${status.name}');
Copy link

Copilot AI Aug 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma after the last field. For consistency with other toString() implementations in this PR, add a comma after 'name'.

Suggested change
buffer.writeln(' name: ${status.name}');
buffer.writeln(' name: ${status.name},');

Copilot uses AI. Check for mistakes.
final buffer = StringBuffer();
buffer.writeln('CoseKey(');
buffer.writeln(' algorithm: $alg,');
buffer.writeln(' params: ${Map<int, dynamic>.from(this)}');
Copy link

Copilot AI Aug 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma after the last field. For consistency with other toString() implementations in this PR, add a comma after 'params'.

Suggested change
buffer.writeln(' params: ${Map<int, dynamic>.from(this)}');
buffer.writeln(' params: ${Map<int, dynamic>.from(this)},');

Copilot uses AI. Check for mistakes.
final buffer = StringBuffer();
buffer.writeln('UnsupportedKey(');
buffer.writeln(' algorithm: $alg,');
buffer.writeln(' params: ${Map<int, dynamic>.from(this)}');
Copy link

Copilot AI Aug 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma after the last field. For consistency with other toString() implementations in this PR, add a comma after 'params'.

Suggested change
buffer.writeln(' params: ${Map<int, dynamic>.from(this)}');
buffer.writeln(' params: ${Map<int, dynamic>.from(this)},');

Copilot uses AI. Check for mistakes.
buffer.writeln('ES256(');
buffer.writeln(' algorithm: $algorithm,');
buffer.writeln(' x: ${x != null ? hex.encode(x) : null},');
buffer.writeln(' y: ${y != null ? hex.encode(y) : null}');
Copy link

Copilot AI Aug 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma after the last field. For consistency with other toString() implementations in this PR, add a comma after 'y'.

Suggested change
buffer.writeln(' y: ${y != null ? hex.encode(y) : null}');
buffer.writeln(' y: ${y != null ? hex.encode(y) : null},');

Copilot uses AI. Check for mistakes.
buffer.writeln('EcdhEsHkdf256(');
buffer.writeln(' algorithm: $algorithm,');
buffer.writeln(' x: ${x != null ? hex.encode(x) : null},');
buffer.writeln(' y: ${y != null ? hex.encode(y) : null}');
Copy link

Copilot AI Aug 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comma after the last field. For consistency with other toString() implementations in this PR, add a comma after 'y'.

Suggested change
buffer.writeln(' y: ${y != null ? hex.encode(y) : null}');
buffer.writeln(' y: ${y != null ? hex.encode(y) : null},');

Copilot uses AI. Check for mistakes.
@Harry-Chen
Copy link
Contributor

As we have discussed before, it would be more elegant and clean to use the native serialization of Dart to convert the data classes from/to JSON. @dangfan What's your opinion on this?

@dangfan
Copy link
Contributor

dangfan commented Aug 16, 2025

As we have discussed before, it would be more elegant and clean to use the native serialization of Dart to convert the data classes from/to JSON. @dangfan What's your opinion on this?

I agree. Shall we finish the server part first and then work on this?

@inuEbisu
Copy link
Contributor Author

Given our earlier discussion to prefer JSON-based serialization over handcrafted toString, this PR (manual toString) has become obsolete. I’ve implemented the json_serializable-based toJson plus a unified toString via mixin on top of main. Rebasing this branch onto main now causes extensive conflicts due to parallel changes. So I would like to close this PR and open a fresh one from main that reflects the JSON approach for a cleaner review. :D

@inuEbisu inuEbisu closed this Aug 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants