Skip to content

Commit

Permalink
PXZ improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Brhsoftco committed Aug 19, 2020
1 parent e20cdf9 commit 007fe52
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions PlexDL.Common.Pxz/Structures/PxzRecordContent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using PlexDL.Common.Pxz.Compressors;
using PlexDL.Common.Enums;
using PlexDL.Common.Pxz.Compressors;
using PlexDL.Common.Security;
using System.Drawing;
using System.Text;
using System.Xml;
Expand All @@ -8,6 +10,9 @@ namespace PlexDL.Common.Pxz.Structures
{
public class PxzRecordContent
{
[XmlIgnore]
private bool _encrypted = false;

public PxzRecordContent()
{
//blank initialiser
Expand Down Expand Up @@ -54,6 +59,11 @@ public XmlDocument ToXmlDocument()

public Image ToImage() => Utilities.ByteToImage(Record);

/// <summary>
/// Determines whether the record's contents have been encrypted via DPAPI
/// </summary>
public bool Encrypted => _encrypted;

/// <summary>
/// Raw compressed base64-encoded (ASCII/UTF8) Gzipped bytes
/// </summary>
Expand All @@ -75,7 +85,15 @@ public byte[] Record
{
get
{
var r = !string.IsNullOrEmpty(RawRecord) ? GZipCompressor.DecompressBytes(RawRecord) : null;
var raw = RawRecord;

if (Encrypted)
{
var provider = new ProtectedString(raw, StringProtectionMode.Decrypt);
raw = provider.ProcessedValue;
}

var r = !string.IsNullOrEmpty(raw) ? GZipCompressor.DecompressBytes(raw) : null;
TmpRecord = r;
return r;
}
Expand Down

0 comments on commit 007fe52

Please sign in to comment.