getMobiKeyV2 static method

List<int> getMobiKeyV2(
  1. String? pid,
  2. MobiData data
)

Implementation

static List<int> getMobiKeyV2(String? pid, MobiData data) {
  String? deviceKey;
  if (pid != null) {
    final pidKey = Uint8List.fromList(pid.codeUnits + "\\0".codeUnits);
    deviceKey = String.fromCharCodes(
        encryptPk1(pidKey, keySize, internalReaderKeyV1));
  }
  List<MobiVoucher> drms = getVouchers(data);
  bool keyExpired = false;
  for (var drm in drms) {
    int tries = 2;
    while (tries != 0) {
      final tryKey = (tries == 2) ? deviceKey : internalReaderKey;
      final tryType = (tries == 2) ? 1 : 3;
      if (tryKey != null && drm.checksum == checkSumDrmKey(tryKey)) {
        final cookie = decryptPk1(drm.cookie, cookieSize, tryKey);
        final ret = verifyCookie(drm.verification, cookie, tryType);
        if (ret == VerificationResult.success) {
          return cookie.sublist(8, 24);
        }
        if (ret == VerificationResult.expired) {
          keyExpired = true;
        }
      }
      tries--;
    }
  }
  if (keyExpired) {
    throw MobiDrmKeyNotFoundException();
  } else {
    throw MobiDrmKeyNotFoundException();
  }
}