diff --git a/LibIRD/IRD.cs b/LibIRD/IRD.cs
index 6de8ef9..b944436 100644
--- a/LibIRD/IRD.cs
+++ b/LibIRD/IRD.cs
@@ -84,19 +84,52 @@ namespace LibIRD
/// D1 key
///
/// 16 bytes
- public byte[] Data1Key { get; set; }
+ public byte[] Data1Key
+ {
+ get { return _data1Key; }
+ set
+ {
+ if (value != null && value.Length == 16)
+ _data1Key = value;
+ else
+ throw new ArgumentException("Data 1 Key must be a byte array of length 16", nameof(value));
+ }
+ }
+ private byte[] _data1Key;
///
/// D2 key
///
/// 16 bytes
- public byte[] Data2Key { get; set; }
+ public byte[] Data2Key
+ {
+ get { return _data2Key; }
+ set
+ {
+ if (value != null && value.Length == 16)
+ _data2Key = value;
+ else
+ throw new ArgumentException("Data 2 Key must be a byte array of length 16", nameof(value));
+}
+ }
+ private byte[] _data2Key;
///
/// Uncompressed PIC data
///
/// 115 bytes
- public byte[] PIC { get; set; }
+ public byte[] PIC
+ {
+ get { return _pic; }
+ set
+ {
+ if (value != null && value.Length == 115)
+ _pic = value;
+ else
+ throw new ArgumentException("PIC must be a byte array of length 115", nameof(value));
+ }
+ }
+ private byte[] _pic;
#endregion
@@ -181,7 +214,7 @@ namespace LibIRD
public byte[][] FileHashes { get; private set; }
///
- /// Gzipped IRD content 32-bit CRC "IEEE 802.3" hash, little endian
+ /// IRD content 32-bit CRC "IEEE 802.3" hash, little endian
///
public uint CRC { get; private set; }
@@ -386,12 +419,7 @@ namespace LibIRD
// Get PIC from log
string discPICStr = "";
for (int i = 0; i < 8; i++)
- {
- line = sr.ReadLine();
- if (line == null)
- throw new InvalidDataException("Incomplete PIC in .getkey.log");
- discPICStr += line;
- }
+ discPICStr += sr.ReadLine() ?? throw new InvalidDataException("Incomplete PIC in .getkey.log");
// Validate PIC from log
if (discPICStr.Length != 256)
throw new InvalidDataException("Unexpected PIC in .getkey.log");
diff --git a/LibIRD/ReIRD.cs b/LibIRD/ReIRD.cs
index c2c0152..952fa71 100644
--- a/LibIRD/ReIRD.cs
+++ b/LibIRD/ReIRD.cs
@@ -209,11 +209,17 @@ namespace LibIRD
// Parse .getkey.log for the Disc Key (Data1Key)
ParseGetKeyLog(getKeyLog);
- // Generate Data 2 using Disc ID, discarding ID from getKeyLog
+ // Generate Data 2 using Disc ID
GenerateD2(GenerateID(size));
+ byte[] d2 = Data2Key;
+ if (!((ReadOnlySpan)Data2Key).SequenceEqual(d2))
+ throw new InvalidDataException("Unexpected Disc ID in .getkey.log");
- // Generate Disc PIC, discarding PIC from getKeyLog
+ // Generate Disc PIC
+ byte[] pic = PIC;
GeneratePIC(size);
+ if (!((ReadOnlySpan) PIC).SequenceEqual(pic))
+ throw new InvalidDataException("Unexpected PIC in .getkey.log");
// Generate Unique Identifier using ISO CRC32
GenerateUID(isoPath);