fromBytes static method

CAAResponseRecord fromBytes({
  1. required String name,
  2. required int ttl,
  3. required Uint8List bytes,
  4. required int offset,
  5. required int length,
})

Implementation

static CAAResponseRecord fromBytes({
    required String name,
    required int ttl,
    required Uint8List bytes,
    required int offset,
    required int length }) {

    if (length < 2) {
        throw FormatException('Invalid CAA record: too short');
    }

    final int flags = bytes[offset];
    final int tagLength = bytes[offset + 1];

    if (length < 2 + tagLength) {
        throw FormatException('Invalid CAA record: tagLength overflow');
    }

    final String tag = String.fromCharCodes(bytes.sublist(offset + 2, offset + 2 + tagLength));
    final String value = String.fromCharCodes(bytes.sublist(offset + 2 + tagLength, offset + length));

    return CAAResponseRecord(
        name: name,
        ttl: ttl,
        flags: flags,
        tag: tag,
        value: value);
}