public void TestBadAlphabetAllowedIfCS() { var g = Guid.NewGuid(); var enc = new Base32Url(false, true, true, "AaCDEFGHIJKLMNOPQRSTUVWXYZ123456"); var o = enc.Encode(g.ToByteArray()); Assert.Equal(g, new Guid(enc.Decode(o))); }
public async Task <string> CreateNewJobOrUpdateDefinition <TJobStep>(string tenantId, string jobDisplayName = null, string jobId = null, JobConfigurationData configuration = null) where TJobStep : IJobStep { if (string.IsNullOrWhiteSpace(jobId)) { jobId = Base32Url.ToBase32String(Guid.NewGuid().ToByteArray()); } configuration = configuration ?? new JobConfigurationData(); ValidateAndFixConfiguration(configuration); var job = new JobData { JobId = jobId, TenantId = tenantId, JobDisplayName = jobDisplayName ?? typeof(TJobStep).Name, JobStepType = typeof(TJobStep).AssemblyQualifiedName, CreationTime = DateTime.UtcNow, CreatedBy = "unknown", Configuration = configuration, Status = new JobStatusData { State = JobState.Initializing, StateTime = DateTime.UtcNow, LastIterationStartTime = DateTime.UtcNow, LastDequeueAttemptTime = DateTime.UtcNow, LastProcessStartTime = DateTime.UtcNow, LastProcessFinishTime = DateTime.UtcNow, LastHealthCheckTime = DateTime.UtcNow, ItemsProcessed = 0, ItemsRequeued = 0, ItemsGeneratedForTargetQueue = 0, EstimatedTotalItems = -1, ProcessingTimeTakenMillis = 0, ItemsFailed = 0, LastFailTime = null, LastFailures = new JobStatusErrorData[0], ExceptionCount = 0, LastExceptionTime = null, LastExceptions = new JobStatusErrorData[0] } }; await JobStore.AddOrUpdateDefinition(job); var queue = Composer.GetComponent <IJobQueue <TJobStep> >(job.Configuration.QueueTypeName); if (queue == null) { throw new CompositionException("JobQueue should be registered"); } await queue.EnsureJobQueueExists(jobId); return(jobId); }
public void NoPaddingEncodeDecode() { var enc = new Base32Url(false, true, false); foreach (var s in rfc4684TestVectors) { Assert.Equal(System.Text.Encoding.ASCII.GetString(enc.Decode(s[1].TrimEnd('='))), s[0]); Assert.Equal(enc.Encode(System.Text.Encoding.ASCII.GetBytes(s[0])), s[1].TrimEnd('=')); } }
public void CaseSensitiveDecodeError() { var enc = new Base32Url(true, true, false); foreach (string[] s in rfc4684TestVectors) { string encodedS1 = s[1].ToLowerInvariant(); Assert.Equal(Encoding.ASCII.GetString(enc.Decode(encodedS1)), s[0]); } }
public void Rfc4648TestVectorsEncodeDecode() { var enc = new Base32Url(true, true, false); foreach (string[] s in rfc4684TestVectors) { Assert.Equal(enc.Encode(Encoding.ASCII.GetBytes(s[0])), s[1]); Assert.Equal(Encoding.ASCII.GetString(enc.Decode(s[1])), s[0]); } }
public void CaseInsensitiveDecode() { var enc = new Base32Url(true, false, false); foreach (var s in rfc4684TestVectors) { #pragma warning disable CA1308 // Normalize strings to uppercase var encodedS1 = s[1].ToLowerInvariant(); #pragma warning restore CA1308 // Normalize strings to uppercase Assert.Equal(System.Text.Encoding.ASCII.GetString(enc.Decode(encodedS1)), s[0]); } }
public void TestAssymetricAlphabet() { var b32 = new Base32Url(false, true, true, Base32Url.Base32CrockfordHumanFriendlyAlphabet); var s = "Hello World!"; var b = Encoding.UTF8.GetBytes(s); var enc = b32.Encode(b); Assert.Equal("91JPRV3F41BPYWKCCGGG", enc); Assert.Equal(s, Encoding.UTF8.GetString(b32.Decode(enc))); // test decode replacing second character which is a 1 above with an I here Assert.Equal(s, Encoding.UTF8.GetString(b32.Decode("9IJPRV3F41BPYWKCCGGG"))); }
public void NoPaddingCaseSensitiveCustomAlphabetsEncodeDecode() { // no vowels (prevents accidental profanity) // no numbers or letters easily mistakable foreach (var alphabet in new[] { "BCDFGHKMNPQRSTVWXYZ23456789bcdfg", "BCDFGHKMNPQRSTVWXYZbcdfghkmnpqrs" }) { var enc = new Base32Url(true, true, false, alphabet); foreach (var s in rfc4684TestVectors) { Assert.Equal(System.Text.Encoding.ASCII.GetString(enc.Decode(enc.Encode(System.Text.Encoding.ASCII.GetBytes(s[0])))), s[0]); } } }
public void NoPaddingCaseInSensitiveCustomAlphabetsEncodeDecode() { // no vowels (prevents accidental profanity) // no numbers or letters easily mistakable foreach (string alphabet in new[] { "BCDFGHKMNPQRSTVWXYZ23456789~!@#$" }) { var enc1 = new Base32Url(true, false, false, alphabet); var enc2 = new Base32Url(true, false, false, alphabet.ToLower()); foreach (string[] s in rfc4684TestVectors) { Assert.Equal(Encoding.ASCII.GetString(enc2.Decode(enc1.Encode(Encoding.ASCII.GetBytes(s[0])))), s[0]); Assert.Equal(Encoding.ASCII.GetString(enc1.Decode(enc2.Encode(Encoding.ASCII.GetBytes(s[0])))), s[0]); } } }
public string GetHashedUserId(string userName) { if (string.IsNullOrEmpty(userName)) { throw new ArgumentException("userName can't be empty", nameof(userName)); } //https://wiki.gnupg.org/EasyGpg2016/PubkeyDistributionConcept //32-char long string constructed of the mapped local part of the email, SHA-1 hashed and z-Base-32 encoded. var sha1 = SHA1.Create(); var hashed = sha1.ComputeHash(Encoding.UTF8.GetBytes(userName)); var base32Encoder = new Base32Url(Base32Url.ZBase32Alphabet); var hu = base32Encoder.Encode(hashed); return(hu); }
public void SequentialValuesSequentialLengths() { var bcv = new Base32Url(false, false, false); for (var j = 1; j < 11; j++) { var d = new byte[j]; for (byte b = 0; b < 255; b++) { for (var i = 0; i < d.Length; i++) { d[i] = (byte)((b + i) % 255); } var r = bcv.Decode(bcv.Encode(d)); var tcnt = -1; var result = Array.TrueForAll(d, b1 => { tcnt++; return(r[tcnt] == d[tcnt]); }); Assert.True(result); } } }