This commit is contained in:
Paul Schneider
2021-08-15 05:31:38 +01:00
parent ae114c68db
commit f6f3473346
56 changed files with 1351 additions and 31 deletions

View File

@ -1,33 +1,45 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace isn
{
internal interface IDataProtector
public interface IDataProtector
{
string Protect(string data);
string UnProtect(string data);
}
class DefaultDataProtector : IDataProtector
public class DefaultDataProtector : IDataProtector
{
private byte delta = 145;
public DefaultDataProtector()
{
}
public string Protect(string data)
{
List<Byte> protd = new List<byte>();
StringBuilder sb = new StringBuilder();
foreach (char c in data)
foreach (byte c in Encoding.UTF8.GetBytes(data))
{
sb.Append(c+13);
protd.Add((byte) (c ^ delta));
}
return sb.ToString();
return System.Convert.ToBase64String(protd.ToArray());
}
public string UnProtect(string data)
{
StringBuilder sb = new StringBuilder();
foreach (char c in data)
List<byte> unps = new List<byte>();
foreach (byte c in System.Convert.FromBase64CharArray(data.ToCharArray(),0,data.Length))
{
sb.Append(c-13);
unps.Add((byte) (c ^ delta));
}
return sb.ToString();
return Encoding.UTF8.GetString(unps.ToArray());
}
}

View File

@ -47,7 +47,7 @@ namespace isn
}
public static IEnumerable<IsnSourceSettings> Sources{ get; protected set; }
private static object StoreApiKey(IEnumerable<string> storeArgs)
private static void StoreApiKey(IEnumerable<string> storeArgs)
{
var args = storeoptions.Parse(storeArgs);
if (shouldShowPushHelp)
@ -62,12 +62,13 @@ namespace isn
EnsureKeyStored(source,keyv);
}
}
throw new NotImplementedException();
}
private static void EnsureKeyStored(string source, string keyv)
{
throw new NotImplementedException();
var pkeyv = _protector.Protect(keyv);
}
}
}

View File

@ -8,6 +8,20 @@ namespace isn
{
partial class Program
{
public const string push = "push";
static OptionSet options = new OptionSet {
{ "h|help", "show this message and exit", h => shouldShowHelp = h != null },
};
static OptionSet pushoptions = new OptionSet {
{ "k|api-key=", "use api key", val => apiKey = apiKey ?? val },
{ "s|source=", "use source", val => source = source ?? val },
{ "h|help", "show this message and exit", h => shouldShowPushHelp = h != null },
};
static OptionSet sourceoptions = new OptionSet {
{ "h|help", "show this message and exit", h => shouldShowSourceHelp = h != null },
};
private static bool shouldShowHelp;
private static bool shouldShowSourceHelp;
private static bool shouldShowPushHelp;
@ -15,7 +29,7 @@ namespace isn
private static string source = null;
private static int pushKO = 0;
private readonly isn.IDataProtector _protector;
private static readonly isn.IDataProtector _protector = new DefaultDataProtector();
static Program()
{
@ -24,17 +38,6 @@ namespace isn
static int Main(string[] args)
{
var options = new OptionSet {
{ "h|help", "show this message and exit", h => shouldShowHelp = h != null },
};
var pushoptions = new OptionSet {
{ "k|api-key=", "use api key", val => apiKey = apiKey ?? val },
{ "s|source=", "use source", val => source = source ?? val },
{ "h|help", "show this message and exit", h => shouldShowPushHelp = h != null },
};
var sourceoptions = new OptionSet {
{ "h|help", "show this message and exit", h => shouldShowSourceHelp = h != null },
};
var commandSet = new CommandSet("isn");
@ -49,9 +52,9 @@ namespace isn
};
var srcCmd = new Command("sources")
{
Run = sargs =>
Run = sargs =>
{
var sourcesCmdSet = new CommandSet("sources")
{
srclst,
@ -75,7 +78,7 @@ namespace isn
};
commandSet.Add(add);
var push = new Command("push")
var pushCmd = new Command(push)
{
Run = async sargs =>
@ -90,10 +93,10 @@ namespace isn
}
List<PushReport> reports = await PushPkgAsync(pargs);
Console.WriteLine(JsonConvert.SerializeObject(reports));
pushKO = reports.Count( r => !r.OK && !r.AlreadyPresent);
pushKO = reports.Count(r => !r.OK && !r.AlreadyPresent);
}
};
commandSet.Add(push);
commandSet.Add(pushCmd);
var setapikey = new Command("set-api-key")
{
Run = sargs => StoreApiKey(sargs)
@ -124,12 +127,12 @@ namespace isn
options.WriteOptionDescriptions(Console.Out);
return 1;
}
int runCode = commandSet.Run(args);
if (runCode == 0 ) if (pushKO>0) return 3;
if (runCode == 0) if (pushKO > 0) return 3;
return runCode;
}
}
}

View File

@ -4,6 +4,9 @@
<TargetFramework>net472</TargetFramework>
<RootNamespace>nuget_cli</RootNamespace>
<UserSecretsId>45b74c62-05bc-4603-95b4-3e80ae2fdf50</UserSecretsId>
<PackageVersion>1.0.1</PackageVersion>
<IsPackable>true</IsPackable>
<PackageLicenseExpression>WTFPL</PackageLicenseExpression>
<IsTool>true</IsTool>
</PropertyGroup>
<ItemGroup>