Skip to content

Commit

Permalink
Update Utiltities.cs to support PGP 2.6.x compatibility
Browse files Browse the repository at this point in the history
PgpLiteralDataGenerator has a constructor that takes a bool indicating whether to use old format. 
If true, it generates literal data objects in the old format. /// This is important if you need compatibility with PGP 2.6.x.

Added bool value, useOldFormat, to all utilities methods constructing PgpLiteralDataGenerator object. Default value false to not break any current client usage of the Utilities class. useOldFormat passed to the PgpLiteralDataGenerator constructor.
  • Loading branch information
magks authored Mar 29, 2023
1 parent 190f56c commit 1d94e2a
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions PgpCore/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,10 @@ public static KeyParameter MakeKeyFromPassPhrase(
public static async Task WriteFileToLiteralDataAsync(
Stream output,
char fileType,
FileInfo file)
FileInfo file,
bool useOldFormat = false)
{
PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator();
PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(useOldFormat);
Stream pOut = lData.Open(output, fileType, file.Name, file.Length, file.LastWriteTime);
await PipeFileContentsAsync(file, pOut, 4096);
lData.Close();
Expand All @@ -327,9 +328,10 @@ public static async Task WriteFileToLiteralDataAsync(
public static void WriteFileToLiteralData(
Stream output,
char fileType,
FileInfo file)
FileInfo file,
bool useOldFormat = false)
{
PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator();
PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(useOldFormat);
Stream pOut = lData.Open(output, fileType, file.Name, file.Length, file.LastWriteTime);
PipeFileContents(file, pOut, 4096);
lData.Close();
Expand All @@ -340,9 +342,10 @@ public static async Task WriteFileToLiteralDataAsync(
Stream output,
char fileType,
FileInfo file,
byte[] buffer)
byte[] buffer,
bool useOldFormat = false)
{
PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator();
PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(useOldFormat);
Stream pOut = lData.Open(output, fileType, file.Name, file.LastWriteTime, buffer);
await PipeFileContentsAsync(file, pOut, buffer.Length);
lData.Close();
Expand All @@ -353,9 +356,10 @@ public static void WriteFileToLiteralData(
Stream output,
char fileType,
FileInfo file,
byte[] buffer)
byte[] buffer,
bool useOldFormat = false)
{
PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator();
PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(useOldFormat);
Stream pOut = lData.Open(output, fileType, file.Name, file.LastWriteTime, buffer);
PipeFileContents(file, pOut, buffer.Length);
lData.Close();
Expand All @@ -365,9 +369,10 @@ public static async Task WriteStreamToLiteralDataAsync(
Stream output,
char fileType,
Stream input,
string name)
string name,
bool useOldFormat = false)
{
PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator();
PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(useOldFormat);
Stream pOut = lData.Open(output, fileType, name, input.Length, DateTime.Now);
await PipeStreamContentsAsync(input, pOut, 4096);
lData.Close();
Expand All @@ -377,9 +382,10 @@ public static void WriteStreamToLiteralData(
Stream output,
char fileType,
Stream input,
string name)
string name,
bool useOldFormat = false)
{
PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator();
PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(useOldFormat);
Stream pOut = lData.Open(output, fileType, name, input.Length, DateTime.Now);
PipeStreamContents(input, pOut, 4096);
lData.Close();
Expand All @@ -390,9 +396,10 @@ public static async Task WriteStreamToLiteralDataAsync(
char fileType,
Stream input,
byte[] buffer,
string name)
string name,
bool useOldFormat = false)
{
PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator();
PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(useOldFormat);
Stream pOut = lData.Open(output, fileType, name, DateTime.Now, buffer);
await PipeStreamContentsAsync(input, pOut, buffer.Length);
lData.Close();
Expand All @@ -403,9 +410,10 @@ public static void WriteStreamToLiteralData(
char fileType,
Stream input,
byte[] buffer,
string name)
string name,
bool useOldFormat = false)
{
PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator();
PgpLiteralDataGenerator lData = new PgpLiteralDataGenerator(useOldFormat);
Stream pOut = lData.Open(output, fileType, name, DateTime.Now, buffer);
PipeStreamContents(input, pOut, buffer.Length);
lData.Close();
Expand Down Expand Up @@ -936,4 +944,4 @@ private static int GetSigningScore(PgpSecretKey key)
return score;
}
}
}
}

0 comments on commit 1d94e2a

Please sign in to comment.