public override Copyright Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { if (reader.TokenType is not JsonTokenType.StartObject) { throw new JsonException(); } string text = string.Empty; CopyrightType type = default; while (reader.Read()) { if (reader.TokenType is JsonTokenType.EndObject) { break; } if (reader.TokenType is not JsonTokenType.PropertyName) { throw new JsonException(); } var propertyName = reader.GetString(); reader.Read(); // Read to next token. switch (propertyName) { case "text": text = reader.GetString() !; break; case "type": type = CopyrightTypeConverter.FromSpotifyString(reader.GetString() !); break; default: reader.Skip(); break; } } return(new(text, type)); }
/// <summary> /// Returns the bus key of the MMC logical unit /// </summary> /// <returns><c>true</c> if the command failed and <paramref name="senseBuffer" /> contains the sense buffer.</returns> /// <param name="buffer">Buffer where the bus key will be stored</param> /// <param name="senseBuffer">Sense buffer.</param> /// <param name="protectionType">The type of protection the logical unit reports</param> /// <param name="timeout">Timeout in seconds.</param> /// <param name="duration">Duration in milliseconds it took for the device to execute the command.</param> public bool ReadBusKey(out byte[] buffer, out byte[] senseBuffer, CopyrightType protectionType, uint timeout, out double duration) { duration = 0; buffer = new byte[0]; senseBuffer = new byte[32]; bool sense = false; byte[] challenge = new byte[_challengeSize]; byte[] key1 = new byte[_keySize]; byte variant = 0; for (byte i = 0; i < 4; i++) { // Invalidate AGID to reset any previous drive communications Agid = i; sense = InvalidateAgid(out buffer, out senseBuffer, DvdCssKeyClass.DvdCssCppmOrCprm, timeout, out duration); // Get AGID if (protectionType == CopyrightType.CSS) { sense = ReportAgidCssCppm(out buffer, out senseBuffer, DvdCssKeyClass.DvdCssCppmOrCprm, timeout, out duration); } if (protectionType == CopyrightType.CPRM) { throw new NotImplementedException(); } if (!sense) { Agid = (byte)(buffer[7] >> 6); break; } } if (sense) { return(true); } for (byte i = 0; i < _challengeSize; i++) { challenge[i] = i; } sense = SendChallenge(out buffer, out senseBuffer, DvdCssKeyClass.DvdCssCppmOrCprm, challenge, timeout, out duration); if (sense) { return(true); } sense = ReportKey1(out buffer, out senseBuffer, DvdCssKeyClass.DvdCssCppmOrCprm, timeout, out duration); if (sense) { return(true); } for (byte i = 0; i < _keySize; i++) { key1[i] = buffer[8 - i]; } for (byte i = 0; i < 32; i++) { CSS.EncryptKey(DvdCssKeyType.Key1, i, challenge, out byte[] keyCheck); if (key1.SequenceEqual(keyCheck)) { variant = i; break; } if (i >= 31) { senseBuffer = null; return(true); } } sense = ReportChallenge(out buffer, out senseBuffer, DvdCssKeyClass.DvdCssCppmOrCprm, timeout, out duration); if (sense) { return(true); } for (byte i = 0; i < _challengeSize; i++) { challenge[i] = buffer[13 - i]; } CSS.EncryptKey(DvdCssKeyType.Key2, variant, challenge, out byte[] key2); sense = SendKey2(out buffer, out senseBuffer, DvdCssKeyClass.DvdCssCppmOrCprm, key2, timeout, out duration); if (sense) { return(true); } key1.CopyTo(challenge, 0); key2.CopyTo(challenge, key1.Length); CSS.EncryptKey(DvdCssKeyType.BusKey, variant, challenge, out buffer); BusKey = buffer; return(false); }
public static string ToSpotifyString(this CopyrightType copyrightType) => copyrightType switch {