Skip to content

Conversation

@tsenger
Copy link
Owner

@tsenger tsenger commented Jan 22, 2026

Breaking Changes

Unified API naming for VDS and IDB

  • DigitalSeal → VdsSeal
  • VdsMessage → VdsMessageGroup
  • Feature → VdsMessage
  • IcaoBarcode → IdbSeal
  • IdbMessage → IdbMessageGroup
  • featureList / getFeature() → messageList / getMessage()
  • MessageConverter → VdsSealCodingRegistry
  • IdbMessageTypeParser → IdbMessageTypeRegistry

New Features

Type-safe value access with MessageValue sealed class

seal.getMessage("DATE_OF_BIRTH")?.let { msg ->
when (val v = msg.value) {
is MessageValue.DateValue -> println(v.date)
is MessageValue.MaskedDateValue -> println(v.value)
else -> println(v)
}
}

Types: ByteValue, StringValue, DateValue, MaskedDateValue, MrzValue, BytesValue

resetToDefaults() added to DataEncoder for test isolation.


Migration

  • valueStr → value.toString()
  • valueBytes → value.rawBytes
  • valueInt → (value as MessageValue.ByteValue).value

This major refactoring introduces a sealed class hierarchy for message values,
providing type-safe access to decoded data while always preserving raw bytes.

## New FeatureValue sealed class (src/commonMain/.../vds/FeatureValue.kt)

The sealed class provides different value types based on the encoding:
- ByteValue: Single byte values (e.g., document type identifiers)
- StringValue: C40 or UTF-8 encoded strings
- DateValue: LocalDate values from encoded dates
- MaskedDateValue: Partially masked date strings
- MrzValue: Formatted MRZ strings with proper line breaks
- BytesValue: Raw byte arrays (fallback for unknown encodings)

Each type provides:
- rawBytes: Always available, original byte array
- decoded: Type-safe access to the decoded value
- toString(): Human-readable string representation

Factory method fromBytes() handles decoding with graceful fallback to
BytesValue if decoding fails.

## Refactored classes

### Feature (internal, VDS)
- Simplified to use FeatureValue instead of valueBytes/valueInt/valueStr

### Message (public API)
- Simplified to use FeatureValue
- API consumers can use when() for type-safe value access

### IdbMessage (internal, IDB)
- Converted from constructor-based to factory methods:
  - fromDerTlv(): Parse from DER TLV
  - fromByteArray(): Parse from raw bytes
  - fromNameAndContent(): Create from name and encoded content
  - fromTagAndContent(): Create from tag and encoded content
  - fromNameAndRawBytes(): Create with raw bytes (for testing)

### DigitalSeal
- Updated getMessage() to create Message with proper MRZ length handling
- Added getMrzLength() helper for MRVA (88) and MRVB (72) formats

### IcaoBarcode
- Updated getMessage() and messageList to use new API
- documentType now uses type-safe FeatureValue.ByteValue casting

### DataEncoder
- Updated encodeDerTlv() methods to create Features with FeatureValue

### IdbMessageGroup
- Builder now uses IdbMessage.fromTagAndContent()

## API Usage Example

```kotlin
val seal = Seal.fromString(barcodeString)

// Simple output
seal.messageList.forEach { msg ->
    println("${msg.messageTypeName}: ${msg.value}")
}

// Type-safe access
seal.getMessage("DATE_OF_BIRTH")?.let { msg ->
    when (val v = msg.value) {
        is FeatureValue.DateValue -> println("Born: ${v.date}")
        is FeatureValue.MaskedDateValue -> println("Masked: ${v.value}")
        else -> println("$v")
    }
}

// Raw bytes always available
val raw = seal.getMessage("MRZ")?.value?.rawBytes
```

## Test updates
- All tests updated to use new API
- valueStr -> value.toString()
- valueBytes -> value.rawBytes
- valueInt -> (value as FeatureValue.ByteValue).value
- IdbMessage constructors -> factory methods
Rename classes to follow consistent naming pattern:
- VdsMessage → VdsMessageGroup (container)
- Feature → VdsFeature (element)
- DigitalSeal → VdsSeal
- IdbMessage → IdbFeature (element)
- IcaoBarcode → IdbSeal

Refactor IdbMessageGroup to match VdsMessageGroup:
- Store List<DerTlv> internally with lazy featureList
- Rename getMessage() → getFeature()
- Rename addMessage() → addFeature()
- Rename messagesList → featureList

Both standards now share identical API structure.
…encoding logic

- Add addFeature(tag, value) method to VdsMessageGroup.Builder for consistency with IdbMessageGroup.Builder
- Extract common encoding logic into DataEncoder.encodeValueByCoding() to eliminate code duplication
- Add public getFeatureTag() and getFeatureCoding() methods to FeatureConverter and DataEncoder
- Simplify Builder implementations in VdsMessageGroup and IdbMessageGroup
- Add test cases for tag-based feature addition
- Rename base types: FeatureCoding → MessageCoding, FeatureValue → MessageValue, FeaturesDto → MessageDto
- Rename entity classes: VdsFeature → VdsMessage, IdbFeature → IdbMessage
- Rename converters: FeatureConverter → MessageConverter, ExtendedFeatureDefinitionRegistry → ExtendedMessageDefinitionRegistry
- Update MessageGroup API: featureList → messageList, addFeature() → addMessage(), getFeature() → getMessage()
- Update JSON resources: features → messages in SealCodings.json and ExtendedMessageDefinitions.json
- Update build config: EXTENDED_FEATURE_DEFINITIONS_JSON → EXTENDED_MESSAGE_DEFINITIONS_JSON
- Update README.md examples to reflect new API naming
- Rename MessageConverter to VdsSealCodingRegistry
- Rename IdbMessageTypeParser to IdbMessageTypeRegistry
- Rename IdbNationalDocumentTypeParser to IdbNationalDocumentTypeRegistry
- Add resetToDefaults() to DataEncoder for test isolation
- Add KDoc documentation to VdsSealCodingRegistry
- Add tests for loadCustom...FromFile functions
- Add custom test resource JSON files
Copy link
Owner Author

@tsenger tsenger left a comment

Choose a reason for hiding this comment

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

fine

@tsenger tsenger merged commit 68d6f87 into main Jan 22, 2026
2 checks passed
@tsenger tsenger deleted the v0.11 branch January 22, 2026 10:27
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.

2 participants