Skip to content

Choose paste format "plaintext", "syntaxhighlighting", "markdown" #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,5 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd
/TestPrivateBinMarkdown
8 changes: 7 additions & 1 deletion PrivateBinSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33403.182
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrivateBinSharp", "PrivateBinSharp\PrivateBinSharp.csproj", "{45153CEC-DFAE-4623-809A-8D4BD2D811A3}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PrivateBinSharp", "PrivateBinSharp\PrivateBinSharp.csproj", "{45153CEC-DFAE-4623-809A-8D4BD2D811A3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestPrivateBinMarkdown", "TestPrivateBinMarkdown\TestPrivateBinMarkdown.csproj", "{47579373-3E2E-44DA-9C95-3EADB83448FD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -15,6 +17,10 @@ Global
{45153CEC-DFAE-4623-809A-8D4BD2D811A3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{45153CEC-DFAE-4623-809A-8D4BD2D811A3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{45153CEC-DFAE-4623-809A-8D4BD2D811A3}.Release|Any CPU.Build.0 = Release|Any CPU
{47579373-3E2E-44DA-9C95-3EADB83448FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{47579373-3E2E-44DA-9C95-3EADB83448FD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{47579373-3E2E-44DA-9C95-3EADB83448FD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{47579373-3E2E-44DA-9C95-3EADB83448FD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
48 changes: 31 additions & 17 deletions PrivateBinSharp/PrivateBinClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,24 @@ public PrivateBinClient(string hostUrl)
/// </summary>
public static string Version => Assembly.GetExecutingAssembly().GetName().Version!.ToString(3);

/// <summary>
/// Create a paste that will be encrypted
/// </summary>
/// <param name="text"></param>
/// <param name="password"></param>
/// <param name="expire"></param>
/// <param name="openDiscussion"></param>
/// <param name="burnAfterReading"></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="Exception"></exception>
public async Task<Paste> CreatePaste(string text, string password, string expire = "5min", bool openDiscussion = false, bool burnAfterReading = false)
/// <summary>
/// Create a paste that will be encrypted
/// </summary>
/// <param name="text"></param>
/// <param name="password"></param>
/// <param name="expire"></param>
/// <param name="openDiscussion"></param>
/// <param name="burnAfterReading"></param>
/// <param name="format"></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
/// <exception cref="Exception"></exception>
public async Task<Paste> CreatePaste(string text,
string password,
string expire = "5min",
bool openDiscussion = false,
bool burnAfterReading = false,
string format = "plaintext")
{
if (string.IsNullOrEmpty(text))
throw new ArgumentException("Paste text can't be empty.");
Expand All @@ -87,14 +93,14 @@ public async Task<Paste> CreatePaste(string text, string password, string expire
Tuple<PasteJson, byte[]> Json;
try
{
Json = GeneratePasteData(text, password, expire, openDiscussion, burnAfterReading);
Json = GeneratePasteData(text, password, expire, openDiscussion, burnAfterReading, format);
}
catch (Exception ex)
{
throw new Exception("Failed to generate encrypted data, " + ex.Message);
}

string body = Newtonsoft.Json.JsonConvert.SerializeObject(Json.Item1);
string body = Newtonsoft.Json.JsonConvert.SerializeObject(Json.Item1);
HttpRequestMessage Req = new HttpRequestMessage(HttpMethod.Post, HostURL)
{
Content = new StringContent(body, Encoding.UTF8)
Expand Down Expand Up @@ -146,7 +152,12 @@ public async Task<Paste> CreatePaste(string text, string password, string expire
};
}

private static Tuple<PasteJson, byte[]> GeneratePasteData(string text, string password, string expire, bool openDiscussion, bool burnAfterReading)
private static Tuple<PasteJson, byte[]> GeneratePasteData(string text,
string password,
string expire,
bool openDiscussion,
bool burnAfterReading,
string format)
{
SecureRandom rng = new();

Expand Down Expand Up @@ -178,8 +189,11 @@ private static Tuple<PasteJson, byte[]> GeneratePasteData(string text, string pa
string compressionType = "none";
int _openDiscussion = openDiscussion ? 1 : 0;
int _burnAfterReading = burnAfterReading ? 1 : 0;
byte[] _format = Array.Empty<byte>();
if (!string.IsNullOrEmpty(format))
_format = UTF8Encoding.UTF8.GetBytes(format);

object[] pasteMetaObj = new object[]
object[] pasteMetaObj = new object[]
{
new object[]
{
Expand All @@ -192,7 +206,7 @@ private static Tuple<PasteJson, byte[]> GeneratePasteData(string text, string pa
cipherMode,
compressionType
},
"plaintext",
format,
_openDiscussion,
_burnAfterReading
};
Expand Down
3 changes: 2 additions & 1 deletion PrivateBinSharp/PrivateBinSharp.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.