addFont method

Future<void> addFont(
  1. ByteReader r
)

Handles a font sent in answer to a request. Files whose content does not match the hash are dropped, so a host cannot poison the cache.

Implementation

Future<void> addFont(ByteReader r) async {
  final hex = _hex(r.bytes(32));
  final familyKey = _offeredFiles[hex];
  if (familyKey == null) return;
  final bytes = Uint8List.fromList(r.rest());
  if (_hex(sha256.convert(bytes).bytes) != hex) return;
  await fontCache.put(hex, bytes);
  await _register(familyKey, hex, bytes);
}