slightly refactor OuterEncryptionUtil.CheckOuterEncryptionHeader

This commit is contained in:
2025-11-25 00:41:22 +03:00
parent 6a7e1b2eae
commit a2f5ccf64b

View File

@@ -18,15 +18,10 @@ public static class OuterEncryptionUtil
public static void CheckOuterEncryptionHeader(FileStream f) public static void CheckOuterEncryptionHeader(FileStream f)
{ {
BinaryReader rd = new(f); BinaryReader rd = new(f);
byte masterSaltLen;
try try
{ {
masterSaltLen = rd.ReadByte(); byte masterSaltLen = rd.ReadByte();
}
catch (EndOfStreamException)
{
throw PassStoreFileException.UnexpectedEndOfFile;
}
if (masterSaltLen < MIN_MASTER_SALT_LEN || masterSaltLen > MAX_MASTER_SALT_LEN) if (masterSaltLen < MIN_MASTER_SALT_LEN || masterSaltLen > MAX_MASTER_SALT_LEN)
{ {
throw PassStoreFileException.InvalidCryptoHeader; throw PassStoreFileException.InvalidCryptoHeader;
@@ -34,15 +29,7 @@ public static class OuterEncryptionUtil
f.Seek(masterSaltLen, SeekOrigin.Current); f.Seek(masterSaltLen, SeekOrigin.Current);
byte encryptAlgo; byte encryptAlgo = rd.ReadByte();
try
{
encryptAlgo = rd.ReadByte();
}
catch (EndOfStreamException)
{
throw PassStoreFileException.UnexpectedEndOfFile;
}
if (encryptAlgo == ENCRYPT_ALGO_AES) if (encryptAlgo == ENCRYPT_ALGO_AES)
{ {
@@ -54,15 +41,7 @@ public static class OuterEncryptionUtil
throw PassStoreFileException.InvalidCryptoHeader; throw PassStoreFileException.InvalidCryptoHeader;
} }
byte keyDerivationFunctionType; byte keyDerivationFunctionType = rd.ReadByte();
try
{
keyDerivationFunctionType = rd.ReadByte();
}
catch (EndOfStreamException)
{
throw PassStoreFileException.UnexpectedEndOfFile;
}
if (keyDerivationFunctionType == KDF_TYPE_AESKDF) if (keyDerivationFunctionType == KDF_TYPE_AESKDF)
{ {
@@ -71,10 +50,6 @@ public static class OuterEncryptionUtil
{ {
nRounds = rd.Read7BitEncodedInt(); nRounds = rd.Read7BitEncodedInt();
} }
catch (EndOfStreamException)
{
throw PassStoreFileException.UnexpectedEndOfFile;
}
catch (FormatException) catch (FormatException)
{ {
throw PassStoreFileException.InvalidCryptoHeader; throw PassStoreFileException.InvalidCryptoHeader;
@@ -87,4 +62,9 @@ public static class OuterEncryptionUtil
f.Seek(32, SeekOrigin.Current); f.Seek(32, SeekOrigin.Current);
} }
} }
catch (EndOfStreamException)
{
throw PassStoreFileException.UnexpectedEndOfFile;
}
}
} }