From 54c4736965fc2f8c714c9d6b103b2ac9f2b448f9 Mon Sep 17 00:00:00 2001 From: Josh Parnham Date: Tue, 8 Mar 2022 15:00:32 +1100 Subject: [PATCH 01/20] Ensure that an OTP's issuer is correctly escaped when it contains a space --- QRCoder/PayloadGenerator.cs | 4 ++-- QRCoderTests/PayloadGeneratorTests.cs | 31 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/QRCoder/PayloadGenerator.cs b/QRCoder/PayloadGenerator.cs index 6275e5be..aa84f2e9 100644 --- a/QRCoder/PayloadGenerator.cs +++ b/QRCoder/PayloadGenerator.cs @@ -2030,11 +2030,11 @@ private void ProcessCommonFields(StringBuilder sb) if (Label != null && Issuer != null) { - label = Issuer + ":" + Label; + label = escapedIssuer + ":" + Label; } else if (Issuer != null) { - label = Issuer; + label = escapedIssuer; } if (label != null) diff --git a/QRCoderTests/PayloadGeneratorTests.cs b/QRCoderTests/PayloadGeneratorTests.cs index f4406bb7..236d74e4 100644 --- a/QRCoderTests/PayloadGeneratorTests.cs +++ b/QRCoderTests/PayloadGeneratorTests.cs @@ -2660,6 +2660,21 @@ public void one_time_password_generator_time_based_generates_with_standard_optio } + [Fact] + [Category("PayloadGenerator/OneTimePassword")] + public void one_time_password_generator_time_based_generates_with_standard_options_escapes_issuer() + { + var pg = new PayloadGenerator.OneTimePassword + { + Secret = "pwq6 5q55", + Issuer = "Google Google", + Label = "test@google.com", + }; + + pg.ToString().ShouldBe("otpauth://totp/Google%20Google:test@google.com?secret=pwq65q55&issuer=Google%20Google"); + } + + [Fact] [Category("PayloadGenerator/OneTimePassword")] public void one_time_password_generator_hmac_based_generates_with_standard_options() @@ -2676,6 +2691,22 @@ public void one_time_password_generator_hmac_based_generates_with_standard_optio pg.ToString().ShouldBe("otpauth://hotp/Google:test@google.com?secret=pwq65q55&issuer=Google&counter=500"); } + [Fact] + [Category("PayloadGenerator/OneTimePassword")] + public void one_time_password_generator_hmac_based_generates_with_standard_options_escapes_issuer() + { + var pg = new PayloadGenerator.OneTimePassword + { + Secret = "pwq6 5q55", + Issuer = "Google Google", + Label = "test@google.com", + Type = PayloadGenerator.OneTimePassword.OneTimePasswordAuthType.HOTP, + Counter = 500, + }; + + pg.ToString().ShouldBe("otpauth://hotp/Google%20Google:test@google.com?secret=pwq65q55&issuer=Google%20Google&counter=500"); + } + [Fact] [Category("PayloadGenerator/ShadowSocksConfig")] From 32c4aa02402a489519e9e649ecf1d84fdcf755b8 Mon Sep 17 00:00:00 2001 From: Josh Parnham Date: Tue, 15 Mar 2022 16:02:02 +1100 Subject: [PATCH 02/20] Check escapedIssuer instead of Issuer --- QRCoder/PayloadGenerator.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QRCoder/PayloadGenerator.cs b/QRCoder/PayloadGenerator.cs index aa84f2e9..95af78c9 100644 --- a/QRCoder/PayloadGenerator.cs +++ b/QRCoder/PayloadGenerator.cs @@ -2028,11 +2028,11 @@ private void ProcessCommonFields(StringBuilder sb) throw new Exception("Label must not have a ':'"); } - if (Label != null && Issuer != null) + if (Label != null && escapedIssuer != null) { label = escapedIssuer + ":" + Label; } - else if (Issuer != null) + else if (escapedIssuer != null) { label = escapedIssuer; } From 0fd25bc19d37389b9057867a00cbae141ef05569 Mon Sep 17 00:00:00 2001 From: Josh Parnham Date: Tue, 15 Mar 2022 16:11:00 +1100 Subject: [PATCH 03/20] Also escape label --- QRCoder/PayloadGenerator.cs | 13 +++++++++---- QRCoderTests/PayloadGeneratorTests.cs | 16 ++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/QRCoder/PayloadGenerator.cs b/QRCoder/PayloadGenerator.cs index 95af78c9..48336a73 100644 --- a/QRCoder/PayloadGenerator.cs +++ b/QRCoder/PayloadGenerator.cs @@ -2012,6 +2012,7 @@ private void ProcessCommonFields(StringBuilder sb) } string strippedSecret = Secret.Replace(" ", ""); string escapedIssuer = null; + string escapedLabel = null; string label = null; if (!String40Methods.IsNullOrWhiteSpace(Issuer)) @@ -2023,14 +2024,18 @@ private void ProcessCommonFields(StringBuilder sb) escapedIssuer = Uri.EscapeDataString(Issuer); } - if (!String40Methods.IsNullOrWhiteSpace(Label) && Label.Contains(":")) + if (!String40Methods.IsNullOrWhiteSpace(Label)) { - throw new Exception("Label must not have a ':'"); + if (Label.Contains(":")) + { + throw new Exception("Label must not have a ':'"); + } + escapedLabel = Uri.EscapeDataString(Label); } - if (Label != null && escapedIssuer != null) + if (escapedLabel != null && escapedIssuer != null) { - label = escapedIssuer + ":" + Label; + label = escapedIssuer + ":" + escapedLabel; } else if (escapedIssuer != null) { diff --git a/QRCoderTests/PayloadGeneratorTests.cs b/QRCoderTests/PayloadGeneratorTests.cs index 236d74e4..2e90e3ce 100644 --- a/QRCoderTests/PayloadGeneratorTests.cs +++ b/QRCoderTests/PayloadGeneratorTests.cs @@ -2656,22 +2656,22 @@ public void one_time_password_generator_time_based_generates_with_standard_optio Label = "test@google.com", }; - pg.ToString().ShouldBe("otpauth://totp/Google:test@google.com?secret=pwq65q55&issuer=Google"); + pg.ToString().ShouldBe("otpauth://totp/Google:test%40google.com?secret=pwq65q55&issuer=Google"); } [Fact] [Category("PayloadGenerator/OneTimePassword")] - public void one_time_password_generator_time_based_generates_with_standard_options_escapes_issuer() + public void one_time_password_generator_time_based_generates_with_standard_options_escapes_issuer_and_label() { var pg = new PayloadGenerator.OneTimePassword { Secret = "pwq6 5q55", Issuer = "Google Google", - Label = "test@google.com", + Label = "test/test@google.com", }; - pg.ToString().ShouldBe("otpauth://totp/Google%20Google:test@google.com?secret=pwq65q55&issuer=Google%20Google"); + pg.ToString().ShouldBe("otpauth://totp/Google%20Google:test%2Ftest%40google.com?secret=pwq65q55&issuer=Google%20Google"); } @@ -2688,23 +2688,23 @@ public void one_time_password_generator_hmac_based_generates_with_standard_optio Counter = 500, }; - pg.ToString().ShouldBe("otpauth://hotp/Google:test@google.com?secret=pwq65q55&issuer=Google&counter=500"); + pg.ToString().ShouldBe("otpauth://hotp/Google:test%40google.com?secret=pwq65q55&issuer=Google&counter=500"); } [Fact] [Category("PayloadGenerator/OneTimePassword")] - public void one_time_password_generator_hmac_based_generates_with_standard_options_escapes_issuer() + public void one_time_password_generator_hmac_based_generates_with_standard_options_escapes_issuer_and_label() { var pg = new PayloadGenerator.OneTimePassword { Secret = "pwq6 5q55", Issuer = "Google Google", - Label = "test@google.com", + Label = "test/test@google.com", Type = PayloadGenerator.OneTimePassword.OneTimePasswordAuthType.HOTP, Counter = 500, }; - pg.ToString().ShouldBe("otpauth://hotp/Google%20Google:test@google.com?secret=pwq65q55&issuer=Google%20Google&counter=500"); + pg.ToString().ShouldBe("otpauth://hotp/Google%20Google:test%2Ftest%40google.com?secret=pwq65q55&issuer=Google%20Google&counter=500"); } From 4e88511005796138b3a7a9b8e63839f7a4fe84cc Mon Sep 17 00:00:00 2001 From: Michael Haren Date: Mon, 27 Feb 2023 12:48:47 -0500 Subject: [PATCH 04/20] url payload generator should detect all-caps protocol --- QRCoder/PayloadGenerator.cs | 4 ++-- QRCoderTests/PayloadGeneratorTests.cs | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/QRCoder/PayloadGenerator.cs b/QRCoder/PayloadGenerator.cs index 6275e5be..4beafa1e 100644 --- a/QRCoder/PayloadGenerator.cs +++ b/QRCoder/PayloadGenerator.cs @@ -311,7 +311,7 @@ public class Url : Payload private readonly string url; /// - /// Generates a link. If not given, http/https protocol will be added. + /// Generates a link. If protocol not given, http protocol will be added. /// /// Link url target public Url(string url) @@ -321,7 +321,7 @@ public Url(string url) public override string ToString() { - return (!this.url.StartsWith("http") ? "http://" + this.url : this.url); + return (!this.url.StartsWith("http", StringComparison.OrdinalIgnoreCase) ? "http://" + this.url : this.url); } } diff --git a/QRCoderTests/PayloadGeneratorTests.cs b/QRCoderTests/PayloadGeneratorTests.cs index f4406bb7..28cfb6b2 100644 --- a/QRCoderTests/PayloadGeneratorTests.cs +++ b/QRCoderTests/PayloadGeneratorTests.cs @@ -744,6 +744,18 @@ public void url_should_build_https() } + [Fact] + [Category("PayloadGenerator/Url")] + public void url_should_build_https_all_caps() + { + var url = "HTTPS://CODE-BUDE.NET"; + + var generator = new PayloadGenerator.Url(url); + + generator.ToString().ShouldBe("HTTPS://CODE-BUDE.NET"); + } + + [Fact] [Category("PayloadGenerator/Url")] public void url_should_add_http() From 0485f5f676e0299071ea4fa50effc4ccd953ebb9 Mon Sep 17 00:00:00 2001 From: Adam Polner Date: Mon, 5 Jun 2023 20:34:29 -0700 Subject: [PATCH 05/20] Fixed typo in readme --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 7e0e6ac7..7ffdda2f 100644 --- a/readme.md +++ b/readme.md @@ -40,7 +40,7 @@ _(More information on how to use Github Packages in Nuget Package Manager can be ## Usage -You only need five lines of code, to generate and view your first QR code. +You only need four lines of code, to generate and view your first QR code. ```csharp QRCodeGenerator qrGenerator = new QRCodeGenerator(); From ddc31586f7aca86680db68da316403da2474f44f Mon Sep 17 00:00:00 2001 From: Timwi Date: Sat, 4 Nov 2023 17:53:43 +0100 Subject: [PATCH 06/20] Fix ASCII QR codes being diagonally mirrored The current implementation of ASCIIQRCode has the X and Y coordinates swapped, resulting in a QR code that is mirrored about the main diagonal. I am not sure why the resulting QR code still scans successfully, but for feature parity with the other formats I propose to correct this. --- QRCoder/ASCIIQRCode.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QRCoder/ASCIIQRCode.cs b/QRCoder/ASCIIQRCode.cs index bffe7cd0..f18d7266 100644 --- a/QRCoder/ASCIIQRCode.cs +++ b/QRCoder/ASCIIQRCode.cs @@ -52,7 +52,7 @@ public string[] GetLineByLineGraphic(int repeatPerModule, string darkColorString var lineBuilder = new StringBuilder(); for (var x = 0; x < QrCodeData.ModuleMatrix.Count - quietZonesModifier; x++) { - var module = QrCodeData.ModuleMatrix[x + quietZonesOffset][((y + verticalNumberOfRepeats) / verticalNumberOfRepeats - 1)+quietZonesOffset]; + var module = QrCodeData.ModuleMatrix[((y + verticalNumberOfRepeats) / verticalNumberOfRepeats - 1)+quietZonesOffset][x + quietZonesOffset]; for (var i = 0; i < repeatPerModule; i++) { lineBuilder.Append(module ? darkColorString : whiteSpaceString); @@ -75,4 +75,4 @@ public static string GetQRCode(string plainText, int pixelsPerModule, string dar return qrCode.GetGraphic(pixelsPerModule, darkColorString, whiteSpaceString, drawQuietZones, endOfLine); } } -} \ No newline at end of file +} From 3dfd8b0409ce07671548763957cbd1ce8b0cf8bd Mon Sep 17 00:00:00 2001 From: Mark Gross Date: Tue, 28 Nov 2023 11:42:51 -0800 Subject: [PATCH 07/20] Fix readme --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 7ffdda2f..d0a22a59 100644 --- a/readme.md +++ b/readme.md @@ -45,8 +45,8 @@ You only need four lines of code, to generate and view your first QR code. ```csharp QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode("The text which should be encoded.", QRCodeGenerator.ECCLevel.Q); -QRCode qrCode = new QRCode(qrCodeData); -Bitmap qrCodeImage = qrCode.GetGraphic(20); +QRCode qrCode = new PngByteQRCode(qrCodeData); +byte[] qrCodeImage = qrCode.GetGraphic(20); ``` ### Optional parameters and overloads From f13a257a8fc486cf3b3362b85b58416a75f57861 Mon Sep 17 00:00:00 2001 From: Shane32 Date: Tue, 2 Apr 2024 01:39:30 -0400 Subject: [PATCH 08/20] Allow SVG exporting under .NET 6 --- QRCoder/SvgQRCode.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/QRCoder/SvgQRCode.cs b/QRCoder/SvgQRCode.cs index e03ce5dc..25ba8c8c 100644 --- a/QRCoder/SvgQRCode.cs +++ b/QRCoder/SvgQRCode.cs @@ -1,4 +1,4 @@ -#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS +#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0_OR_GREATER using QRCoder.Extensions; using System; using System.Collections; @@ -11,9 +11,6 @@ namespace QRCoder { -#if NET6_0_WINDOWS - [System.Runtime.Versioning.SupportedOSPlatform("windows")] -#endif public class SvgQRCode : AbstractQRCode, IDisposable { /// @@ -270,13 +267,16 @@ public class SvgLogo private object _logoRaw; private bool _isEmbedded; - +#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS /// /// Create a logo object to be used in SvgQRCode renderer /// /// Logo to be rendered as Bitmap/rasterized graphic /// Degree of percentage coverage of the QR code by the logo /// If true, the background behind the logo will be cleaned +#if NET6_0_WINDOWS + [System.Runtime.Versioning.SupportedOSPlatform("windows")] +#endif public SvgLogo(Bitmap iconRasterized, int iconSizePercent = 15, bool fillLogoBackground = true) { _iconSizePercent = iconSizePercent; @@ -293,6 +293,7 @@ public SvgLogo(Bitmap iconRasterized, int iconSizePercent = 15, bool fillLogoBac _logoRaw = iconRasterized; _isEmbedded = false; } +#endif /// /// Create a logo object to be used in SvgQRCode renderer @@ -379,9 +380,6 @@ public enum MediaType : int } } -#if NET6_0_WINDOWS - [System.Runtime.Versioning.SupportedOSPlatform("windows")] -#endif public static class SvgQRCodeHelper { public static string GetQRCode(string plainText, int pixelsPerModule, string darkColorHex, string lightColorHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true, SizingMode sizingMode = SizingMode.WidthHeightAttribute, SvgLogo logo = null) From aecf20a1ae06166ddea52202c579181f2375a080 Mon Sep 17 00:00:00 2001 From: Shane32 Date: Tue, 2 Apr 2024 01:42:56 -0400 Subject: [PATCH 09/20] Enable tests --- QRCoderTests/SvgQRCodeRendererTests.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/QRCoderTests/SvgQRCodeRendererTests.cs b/QRCoderTests/SvgQRCodeRendererTests.cs index b0620594..431325cb 100644 --- a/QRCoderTests/SvgQRCodeRendererTests.cs +++ b/QRCoderTests/SvgQRCodeRendererTests.cs @@ -1,4 +1,4 @@ -#if !NETCOREAPP1_1 && !NET6_0 +#if !NETCOREAPP1_1 using System; using Xunit; using QRCoder; @@ -103,6 +103,7 @@ public void can_render_svg_qrcode_without_quietzones_hex() result.ShouldBe("4ab0417cc6127e347ca1b2322c49ed7d"); } +#if !NET6_0 [Fact] [Category("QRRenderer/SvgQRCode")] public void can_render_svg_qrcode_with_png_logo() @@ -121,6 +122,7 @@ public void can_render_svg_qrcode_with_png_logo() var result = HelperFunctions.StringToHash(svg); result.ShouldBe("78e02e8ba415f15817d5ed88c4afca31"); } +#endif [Fact] [Category("QRRenderer/SvgQRCode")] From b8654c64115833eedb49557909dc8f2d1def98a1 Mon Sep 17 00:00:00 2001 From: Shane32 Date: Tue, 2 Apr 2024 02:04:42 -0400 Subject: [PATCH 10/20] Support passing PNG logos directly to SvgLogo --- QRCoder/SvgQRCode.cs | 18 +++++++++++++++++- QRCoderTests/SvgQRCodeRendererTests.cs | 23 +++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/QRCoder/SvgQRCode.cs b/QRCoder/SvgQRCode.cs index e03ce5dc..657b8a9a 100644 --- a/QRCoder/SvgQRCode.cs +++ b/QRCoder/SvgQRCode.cs @@ -285,7 +285,7 @@ public SvgLogo(Bitmap iconRasterized, int iconSizePercent = 15, bool fillLogoBac using (var bitmap = new Bitmap(iconRasterized)) { bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png); - _logoData = Convert.ToBase64String(ms.GetBuffer(), Base64FormattingOptions.None); + _logoData = Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length, Base64FormattingOptions.None); } } _mediaType = MediaType.PNG; @@ -311,6 +311,22 @@ public SvgLogo(string iconVectorized, int iconSizePercent = 15, bool fillLogoBac _isEmbedded = iconEmbedded; } + /// + /// Create a logo object to be used in SvgQRCode renderer + /// + /// Logo to be rendered as PNG + /// Degree of percentage coverage of the QR code by the logo + /// If true, the background behind the logo will be cleaned + public SvgLogo(byte[] iconRasterized, int iconSizePercent = 15, bool fillLogoBackground = true) + { + _iconSizePercent = iconSizePercent; + _logoData = Convert.ToBase64String(iconRasterized, Base64FormattingOptions.None); + _mediaType = MediaType.PNG; + _fillLogoBackground = fillLogoBackground; + _logoRaw = iconRasterized; + _isEmbedded = false; + } + /// /// Returns the raw logo's data /// diff --git a/QRCoderTests/SvgQRCodeRendererTests.cs b/QRCoderTests/SvgQRCodeRendererTests.cs index b0620594..50a258bd 100644 --- a/QRCoderTests/SvgQRCodeRendererTests.cs +++ b/QRCoderTests/SvgQRCodeRendererTests.cs @@ -105,7 +105,7 @@ public void can_render_svg_qrcode_without_quietzones_hex() [Fact] [Category("QRRenderer/SvgQRCode")] - public void can_render_svg_qrcode_with_png_logo() + public void can_render_svg_qrcode_with_png_logo_bitmap() { //Create QR code var gen = new QRCodeGenerator(); @@ -119,7 +119,26 @@ public void can_render_svg_qrcode_with_png_logo() var svg = new SvgQRCode(data).GetGraphic(10, Color.DarkGray, Color.White, logo: logoObj); var result = HelperFunctions.StringToHash(svg); - result.ShouldBe("78e02e8ba415f15817d5ed88c4afca31"); + result.ShouldBe("7d53f25af04e52b20550deb2e3589e96"); + } + + [Fact] + [Category("QRRenderer/SvgQRCode")] + public void can_render_svg_qrcode_with_png_logo_bytearray() + { + //Create QR code + var gen = new QRCodeGenerator(); + var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.H); + + //Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346 + var logoBitmap = System.IO.File.ReadAllBytes(GetAssemblyPath() + "\\assets\\noun_software engineer_2909346.png"); + var logoObj = new SvgQRCode.SvgLogo(iconRasterized: logoBitmap, 15); + logoObj.GetMediaType().ShouldBe(SvgQRCode.SvgLogo.MediaType.PNG); + + var svg = new SvgQRCode(data).GetGraphic(10, Color.DarkGray, Color.White, logo: logoObj); + + var result = HelperFunctions.StringToHash(svg); + result.ShouldBe("7d53f25af04e52b20550deb2e3589e96"); } [Fact] From 39660beb7ccfdeb4decb3315ff981f2325a409ba Mon Sep 17 00:00:00 2001 From: Shane32 Date: Tue, 2 Apr 2024 02:18:37 -0400 Subject: [PATCH 11/20] Update --- QRCoderTests/SvgQRCodeRendererTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QRCoderTests/SvgQRCodeRendererTests.cs b/QRCoderTests/SvgQRCodeRendererTests.cs index 431325cb..f2d11a35 100644 --- a/QRCoderTests/SvgQRCodeRendererTests.cs +++ b/QRCoderTests/SvgQRCodeRendererTests.cs @@ -103,7 +103,7 @@ public void can_render_svg_qrcode_without_quietzones_hex() result.ShouldBe("4ab0417cc6127e347ca1b2322c49ed7d"); } -#if !NET6_0 +#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS [Fact] [Category("QRRenderer/SvgQRCode")] public void can_render_svg_qrcode_with_png_logo() From 6d895ad41a035d9d934bdcdf2121d4d364f92836 Mon Sep 17 00:00:00 2001 From: Shane32 Date: Tue, 2 Apr 2024 10:07:09 -0400 Subject: [PATCH 12/20] Fix tests locally --- QRCoderTests/ArtQRCodeRendererTests.cs | 20 ------------------ QRCoderTests/PngByteQRCodeRendererTests.cs | 4 ---- QRCoderTests/QRCodeRendererTests.cs | 24 ---------------------- 3 files changed, 48 deletions(-) diff --git a/QRCoderTests/ArtQRCodeRendererTests.cs b/QRCoderTests/ArtQRCodeRendererTests.cs index bcd32c9f..6657a7f4 100644 --- a/QRCoderTests/ArtQRCodeRendererTests.cs +++ b/QRCoderTests/ArtQRCodeRendererTests.cs @@ -23,11 +23,7 @@ public void can_create_standard_qrcode_graphic() var bmp = new ArtQRCode(data).GetGraphic(10); var result = HelperFunctions.BitmapToHash(bmp); -#if NET35_OR_GREATER || NET40_OR_GREATER - result.ShouldBe("11ebdda91b9632d016798cb6de2f5339"); -#else result.ShouldBe("cb38c3156eaf13cdfba699bdafc3a84c"); -#endif } [Fact] @@ -40,11 +36,7 @@ public void can_create_standard_qrcode_graphic_with_custom_finder() var bmp = new ArtQRCode(data).GetGraphic(10, Color.Black, Color.White, Color.Transparent, finderPatternImage: finder); var result = HelperFunctions.BitmapToHash(bmp); -#if NET35_OR_GREATER || NET40_OR_GREATER - result.ShouldBe("c54a7389ae995abc838f0d228acc3bad"); -#else result.ShouldBe("1102c0c6f235eaf4c3ac639f82f17bfa"); -#endif } [Fact] @@ -56,11 +48,7 @@ public void can_create_standard_qrcode_graphic_without_quietzone() var bmp = new ArtQRCode(data).GetGraphic(10, Color.Black, Color.White, Color.Transparent, drawQuietZones: false); var result = HelperFunctions.BitmapToHash(bmp); -#if NET35_OR_GREATER || NET40_OR_GREATER - result.ShouldBe("550f31b988ff12d5f8429ef19d9d5a0c"); -#else result.ShouldBe("632315c8695416fc82fe06a202688433"); -#endif } [Fact] @@ -74,11 +62,7 @@ public void can_create_standard_qrcode_graphic_with_background() var result = HelperFunctions.BitmapToHash(bmp); -#if NET35_OR_GREATER || NET40_OR_GREATER - result.ShouldBe("2caa9c0ee8fcb4a93841debb58cf41bc"); -#else result.ShouldBe("bbea08507282773175cfe7b52f0ddae4"); -#endif } [Fact] @@ -112,11 +96,7 @@ public void can_render_artqrcode_from_helper() var bmp = ArtQRCodeHelper.GetQRCode("A", 10, Color.Black, Color.White, Color.Transparent, QRCodeGenerator.ECCLevel.L); var result = HelperFunctions.BitmapToHash(bmp); -#if NET35_OR_GREATER || NET40_OR_GREATER - result.ShouldBe("fea51114bc4ff893542a1c0574c82a07"); -#else result.ShouldBe("57ecaa9bdeadcdcbeac8a19d734907ff"); -#endif } } } diff --git a/QRCoderTests/PngByteQRCodeRendererTests.cs b/QRCoderTests/PngByteQRCodeRendererTests.cs index 7be21684..0bba6e82 100644 --- a/QRCoderTests/PngByteQRCodeRendererTests.cs +++ b/QRCoderTests/PngByteQRCodeRendererTests.cs @@ -107,11 +107,7 @@ public void can_render_pngbyte_qrcode_color_without_quietzones() var bmp = (Bitmap)Image.FromStream(mStream); bmp.MakeTransparent(Color.Transparent); var result = HelperFunctions.BitmapToHash(bmp); -#if NET35_OR_GREATER || NET40_OR_GREATER - result.ShouldBe("75be11d582575617d2490c54b69e844e"); -#else result.ShouldBe("fbbc8255ebf3e4f4a1d21f0dd15f76f8"); -#endif } #endif } diff --git a/QRCoderTests/QRCodeRendererTests.cs b/QRCoderTests/QRCodeRendererTests.cs index b7414e2b..ed77ec5f 100644 --- a/QRCoderTests/QRCodeRendererTests.cs +++ b/QRCoderTests/QRCodeRendererTests.cs @@ -46,11 +46,7 @@ public void can_create_qrcode_standard_graphic_without_quietzones() var bmp = new QRCode(data).GetGraphic(5, Color.Black, Color.White, false); var result = HelperFunctions.BitmapToHash(bmp); -#if NET35_OR_GREATER || NET40_OR_GREATER - result.ShouldBe("329e1664f57cbe7332d8d4db04c1d480"); -#else result.ShouldBe("d703e54a0ba541c6ea69e3d316e394e7"); -#endif } @@ -65,11 +61,7 @@ public void can_create_qrcode_with_transparent_logo_graphic() var bmp = new QRCode(data).GetGraphic(10, Color.Black, Color.Transparent, icon: (Bitmap)Image.FromFile(HelperFunctions.GetAssemblyPath() + "\\assets\\noun_software engineer_2909346.png")); //Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346 var result = HelperFunctions.BitmapToHash(bmp); -#if NET35_OR_GREATER || NET40_OR_GREATER - result.ShouldBe("ee65d96c3013f6032b561cc768251eef"); -#else result.ShouldBe("150f8fc7dae4487ba2887d2b2bea1c25"); -#endif } [Fact] @@ -83,11 +75,7 @@ public void can_create_qrcode_with_non_transparent_logo_graphic() //Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346 var result = HelperFunctions.BitmapToHash(bmp); -#if NET35_OR_GREATER || NET40_OR_GREATER - result.ShouldBe("1d718f06f904af4a46748f02af2d4eec"); -#else result.ShouldBe("c46a7ec51bf978d7a882059c322ca69d"); -#endif } [Fact] @@ -102,11 +90,7 @@ public void can_create_qrcode_with_logo_and_with_transparent_border() var bmp = new QRCode(data).GetGraphic(10, Color.Black, Color.Transparent, icon: logo, iconBorderWidth: 6); //Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346 var result = HelperFunctions.BitmapToHash(bmp); -#if NET35_OR_GREATER || NET40_OR_GREATER - result.ShouldBe("ee65d96c3013f6032b561cc768251eef"); -#else result.ShouldBe("150f8fc7dae4487ba2887d2b2bea1c25"); -#endif } [Fact] @@ -121,11 +105,7 @@ public void can_create_qrcode_with_logo_and_with_standard_border() var bmp = new QRCode(data).GetGraphic(10, Color.Black, Color.White, icon: logo, iconBorderWidth: 6); //Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346 var result = HelperFunctions.BitmapToHash(bmp); -#if NET35_OR_GREATER || NET40_OR_GREATER - result.ShouldBe("52207bd86ca5a532fb2095dbaa0ae04c"); -#else result.ShouldBe("1c926ea1d48f42fdf8e6f1438b774cdd"); -#endif } [Fact] @@ -140,11 +120,7 @@ public void can_create_qrcode_with_logo_and_with_custom_border() var bmp = new QRCode(data).GetGraphic(10, Color.Black, Color.Transparent, icon: logo, iconBorderWidth: 6, iconBackgroundColor: Color.DarkGreen); //Used logo is licensed under public domain. Ref.: https://thenounproject.com/Iconathon1/collection/redefining-women/?i=2909346 var result = HelperFunctions.BitmapToHash(bmp); -#if NET35_OR_GREATER || NET40_OR_GREATER - result.ShouldBe("d2f20d34a973d92b9c3e05db1393b331"); -#else result.ShouldBe("9a06bfbb72df999b6290b5af5c4037cb"); -#endif } From ac03f1ea1e86c841b477d60c21496cb709cae6c6 Mon Sep 17 00:00:00 2001 From: Shane32 Date: Tue, 2 Apr 2024 10:11:53 -0400 Subject: [PATCH 13/20] Bump workflow versions --- .github/workflows/wf-build-release-ci.yml | 18 +++++++++--------- .github/workflows/wf-build-release.yml | 16 ++++++++-------- .github/workflows/wf-build-test.yml | 14 +++++++------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.github/workflows/wf-build-release-ci.yml b/.github/workflows/wf-build-release-ci.yml index 1f096321..f4d37590 100644 --- a/.github/workflows/wf-build-release-ci.yml +++ b/.github/workflows/wf-build-release-ci.yml @@ -10,11 +10,11 @@ jobs: env: ACTIONS_ALLOW_UNSECURE_COMMANDS: true steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 name: Checkout Code - name: Install additional .NET SDKs - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: | 1.0.x @@ -26,7 +26,7 @@ jobs: uses: microsoft/setup-msbuild@v1 - name: Setup NuGet - uses: NuGet/setup-nuget@v1.0.2 + uses: NuGet/setup-nuget@v2 - name: Restore NuGet Packages run: nuget restore QRCoder.sln @@ -35,7 +35,7 @@ jobs: run: msbuild QRCoder.sln /p:Configuration=Release /p:NoWarn="1182" /p:NoWarn="1701" /nr:false /t:Rebuild - name: Upload artifacts - uses: actions/upload-artifact@v1.0.0 + uses: actions/upload-artifact@v4 with: name: Compiled project path: D:\a\qrcoder\qrcoder @@ -45,13 +45,13 @@ jobs: runs-on: windows-2019 steps: - name: Download artifacts - uses: actions/download-artifact@v1.0.0 + uses: actions/download-artifact@v4 with: name: Compiled project path: D:\a\qrcoder\qrcoder - name: Install additional .NET SDKs - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: | 1.0.x @@ -126,13 +126,13 @@ jobs: GH_PKG_SEC: ${{ secrets.GH_PKG_REPO }} steps: - name: Download artifacts - uses: actions/download-artifact@v1.0.0 + uses: actions/download-artifact@v4 with: name: Compiled project path: D:\a\qrcoder\qrcoder - name: Install additional .NET SDKs - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: | 1.0.x @@ -177,6 +177,6 @@ jobs: runs-on: windows-2019 steps: - name: Delete artifacts - uses: GeekyEggo/delete-artifact@v1.0.0 + uses: GeekyEggo/delete-artifact@v5 with: name: Compiled project diff --git a/.github/workflows/wf-build-release.yml b/.github/workflows/wf-build-release.yml index 003541be..d28f7efe 100644 --- a/.github/workflows/wf-build-release.yml +++ b/.github/workflows/wf-build-release.yml @@ -11,11 +11,11 @@ jobs: env: ACTIONS_ALLOW_UNSECURE_COMMANDS: true steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 name: Checkout Code - name: Install additional .NET SDKs - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: | 1.0.x @@ -27,7 +27,7 @@ jobs: uses: microsoft/setup-msbuild@v1 - name: Setup NuGet - uses: NuGet/setup-nuget@v1.0.2 + uses: NuGet/setup-nuget@v2 - name: Restore NuGet Packages run: nuget restore QRCoder.sln @@ -36,7 +36,7 @@ jobs: run: msbuild QRCoder.sln /p:Configuration=Release /p:NoWarn="1182" /p:NoWarn="1701" /nr:false /t:Rebuild - name: Upload artifacts - uses: actions/upload-artifact@v1.0.0 + uses: actions/upload-artifact@v4 with: name: Compiled project path: D:\a\qrcoder\qrcoder @@ -46,7 +46,7 @@ jobs: runs-on: windows-2019 steps: - name: Download artifacts - uses: actions/download-artifact@v1.0.0 + uses: actions/download-artifact@v4 with: name: Compiled project path: D:\a\qrcoder\qrcoder @@ -126,13 +126,13 @@ jobs: GH_PKG_SEC: ${{ secrets.GH_PKG_REPO }} steps: - name: Download artifacts - uses: actions/download-artifact@v1.0.0 + uses: actions/download-artifact@v4 with: name: Compiled project path: D:\a\qrcoder\qrcoder - name: Install additional .NET SDKs - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: | 1.0.x @@ -171,6 +171,6 @@ jobs: runs-on: windows-2019 steps: - name: Delete artifacts - uses: GeekyEggo/delete-artifact@v1.0.0 + uses: GeekyEggo/delete-artifact@v5 with: name: Compiled project diff --git a/.github/workflows/wf-build-test.yml b/.github/workflows/wf-build-test.yml index d6d016ec..7947f200 100644 --- a/.github/workflows/wf-build-test.yml +++ b/.github/workflows/wf-build-test.yml @@ -10,11 +10,11 @@ jobs: env: ACTIONS_ALLOW_UNSECURE_COMMANDS: true steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 name: Checkout Code - name: Install additional .NET SDKs - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: | 1.0.x @@ -26,7 +26,7 @@ jobs: uses: microsoft/setup-msbuild@v1 - name: Setup NuGet - uses: NuGet/setup-nuget@v1.0.2 + uses: NuGet/setup-nuget@v2 - name: Restore NuGet Packages run: nuget restore QRCoder.sln @@ -35,7 +35,7 @@ jobs: run: msbuild QRCoder.sln /p:Configuration=Release /p:NoWarn="1182" /p:NoWarn="1701" /nr:false /t:Rebuild - name: Upload artifacts - uses: actions/upload-artifact@v1.0.0 + uses: actions/upload-artifact@v4 with: name: Compiled project path: D:\a\qrcoder\qrcoder @@ -45,13 +45,13 @@ jobs: runs-on: windows-2019 steps: - name: Download artifacts - uses: actions/download-artifact@v1.0.0 + uses: actions/download-artifact@v4 with: name: Compiled project path: D:\a\qrcoder\qrcoder - name: Install additional .NET SDKs - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v4 with: dotnet-version: | 1.0.x @@ -89,6 +89,6 @@ jobs: runs-on: windows-2019 steps: - name: Delete artifacts - uses: GeekyEggo/delete-artifact@v1.0.0 + uses: GeekyEggo/delete-artifact@v5 with: name: Compiled project From 4b8fafd59c208716863aedbb1afb25a588c77680 Mon Sep 17 00:00:00 2001 From: Shane32 Date: Tue, 2 Apr 2024 17:26:16 -0400 Subject: [PATCH 14/20] Update tests --- QRCoderTests/SvgQRCodeRendererTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/QRCoderTests/SvgQRCodeRendererTests.cs b/QRCoderTests/SvgQRCodeRendererTests.cs index b6023c5c..0981e6e2 100644 --- a/QRCoderTests/SvgQRCodeRendererTests.cs +++ b/QRCoderTests/SvgQRCodeRendererTests.cs @@ -120,8 +120,9 @@ public void can_render_svg_qrcode_with_png_logo_bitmap() var svg = new SvgQRCode(data).GetGraphic(10, Color.DarkGray, Color.White, logo: logoObj); var result = HelperFunctions.StringToHash(svg); - result.ShouldBe("7d53f25af04e52b20550deb2e3589e96"); + result.ShouldBe("78e02e8ba415f15817d5ed88c4afca31"); } +#endif [Fact] [Category("QRRenderer/SvgQRCode")] @@ -141,7 +142,6 @@ public void can_render_svg_qrcode_with_png_logo_bytearray() var result = HelperFunctions.StringToHash(svg); result.ShouldBe("7d53f25af04e52b20550deb2e3589e96"); } -#endif [Fact] [Category("QRRenderer/SvgQRCode")] From 08b2ef9d71f438ff7de2923673340d1f8cc3c0ea Mon Sep 17 00:00:00 2001 From: Shane32 Date: Tue, 2 Apr 2024 18:30:17 -0400 Subject: [PATCH 15/20] Update PostscriptQRCode so it runs on Linux --- QRCoder/PostscriptQRCode.cs | 9 +- QRCoderTests/PostscriptQRCodeRendererTests.cs | 91 +++++++++++++++++++ 2 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 QRCoderTests/PostscriptQRCodeRendererTests.cs diff --git a/QRCoder/PostscriptQRCode.cs b/QRCoder/PostscriptQRCode.cs index 710551d1..d0484a9b 100644 --- a/QRCoder/PostscriptQRCode.cs +++ b/QRCoder/PostscriptQRCode.cs @@ -1,4 +1,4 @@ -#if NETFRAMEWORK || NETSTANDARD2_0 || NET5_0 || NET6_0_WINDOWS +#if !NETSTANDARD1_3 using System; using System.Drawing; using static QRCoder.QRCodeGenerator; @@ -6,9 +6,6 @@ namespace QRCoder { -#if NET6_0_WINDOWS - [System.Runtime.Versioning.SupportedOSPlatform("windows")] -#endif public class PostscriptQRCode : AbstractQRCode, IDisposable { /// @@ -143,9 +140,6 @@ sc sc scale "; } -#if NET6_0_WINDOWS - [System.Runtime.Versioning.SupportedOSPlatform("windows")] -#endif public static class PostscriptQRCodeHelper { public static string GetQRCode(string plainText, int pointsPerModule, string darkColorHex, string lightColorHex, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1, bool drawQuietZones = true, bool epsFormat = false) @@ -157,5 +151,4 @@ public static string GetQRCode(string plainText, int pointsPerModule, string dar } } } - #endif \ No newline at end of file diff --git a/QRCoderTests/PostscriptQRCodeRendererTests.cs b/QRCoderTests/PostscriptQRCodeRendererTests.cs new file mode 100644 index 00000000..a71db527 --- /dev/null +++ b/QRCoderTests/PostscriptQRCodeRendererTests.cs @@ -0,0 +1,91 @@ +#if !NETCOREAPP1_1 +using QRCoder; +using QRCoderTests.Helpers; +using QRCoderTests.Helpers.XUnitExtenstions; +using Shouldly; +using System; +using System.Drawing; +using System.IO; +using System.Text.RegularExpressions; +using Xunit; + +namespace QRCoderTests +{ + public class PostscriptQRCodeRendererTests + { + [Fact] + [Category("QRRenderer/PostscriptQRCode")] + public void can_render_postscript_qrcode_simple() + { + //Create QR code + var gen = new QRCodeGenerator(); + var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.L); + var ps = new PostscriptQRCode(data).GetGraphic(5); + + var result = HelperFunctions.StringToHash(RemoveCreationDate(ps)); + result.ShouldBe("06b90d1e64bf022a248453e5f91101a0"); + } + + [Fact] + [Category("QRRenderer/PostscriptQRCode")] + public void can_render_postscript_qrcode_eps() + { + //Create QR code + var gen = new QRCodeGenerator(); + var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.L); + var ps = new PostscriptQRCode(data).GetGraphic(5, true); + + var result = HelperFunctions.StringToHash(RemoveCreationDate(ps)); + result.ShouldBe("50f6152cdb0b685595d80e7888712d3b"); + } + + [Fact] + [Category("QRRenderer/PostscriptQRCode")] + public void can_render_postscript_qrcode_size() + { + //Create QR code + var gen = new QRCodeGenerator(); + var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.L); + var ps = new PostscriptQRCode(data).GetGraphic(new Size(33, 33)); + + var result = HelperFunctions.StringToHash(RemoveCreationDate(ps)); + result.ShouldBe("49c7faaafef312eb4b6ea1fec195e63d"); + } + + [Fact] + [Category("QRRenderer/PostscriptQRCode")] + public void can_render_postscript_qrcode_size_no_quiet_zones() + { + //Create QR code + var gen = new QRCodeGenerator(); + var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.L); + var ps = new PostscriptQRCode(data).GetGraphic(new Size(50, 50), false); + + var result = HelperFunctions.StringToHash(RemoveCreationDate(ps)); + result.ShouldBe("9bfa0468e125d9815a39902133a10762"); + } + + [Fact] + [Category("QRRenderer/PostscriptQRCode")] + public void can_render_postscript_qrcode_colors() + { + //Create QR code + var gen = new QRCodeGenerator(); + var data = gen.CreateQrCode("This is a quick test! 123#?", QRCodeGenerator.ECCLevel.L); + var ps = new PostscriptQRCode(data).GetGraphic(5, Color.Red, Color.Blue); + + var result = HelperFunctions.StringToHash(RemoveCreationDate(ps)); + result.ShouldBe("2e001d7f67a446eb1b5df32ff5321808"); + } + + private static string RemoveCreationDate(string text) + { + // Regex pattern to match lines that start with %%CreationDate: followed by any characters until the end of the line + string pattern = @"%%CreationDate:.*\r?\n?"; + + // Use Regex.Replace to remove matching lines + return Regex.Replace(text, pattern, string.Empty, RegexOptions.Multiline); + } + } +} +#endif \ No newline at end of file From b71781e351cace79112d7d7a7d4b6488c9e82c73 Mon Sep 17 00:00:00 2001 From: Raffael Herrmann Date: Wed, 3 Apr 2024 11:05:46 +0200 Subject: [PATCH 16/20] Updated Github token for workflows --- .github/workflows/wf-build-release-ci.yml | 2 +- .github/workflows/wf-build-release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wf-build-release-ci.yml b/.github/workflows/wf-build-release-ci.yml index f4d37590..91b9bb5b 100644 --- a/.github/workflows/wf-build-release-ci.yml +++ b/.github/workflows/wf-build-release-ci.yml @@ -123,7 +123,7 @@ jobs: needs: test runs-on: windows-2019 env: - GH_PKG_SEC: ${{ secrets.GH_PKG_REPO }} + GH_PKG_SEC: ${{ secrets.GITHUB_TOKEN }} steps: - name: Download artifacts uses: actions/download-artifact@v4 diff --git a/.github/workflows/wf-build-release.yml b/.github/workflows/wf-build-release.yml index d28f7efe..530b472f 100644 --- a/.github/workflows/wf-build-release.yml +++ b/.github/workflows/wf-build-release.yml @@ -123,7 +123,7 @@ jobs: needs: test runs-on: windows-2019 env: - GH_PKG_SEC: ${{ secrets.GH_PKG_REPO }} + GH_PKG_SEC: ${{ secrets.GITHUB_TOKEN }} steps: - name: Download artifacts uses: actions/download-artifact@v4 From d25f745eea370294f15b5681fd3f7aefe2bf55a5 Mon Sep 17 00:00:00 2001 From: Raffael Herrmann Date: Sun, 7 Apr 2024 20:49:48 +0200 Subject: [PATCH 17/20] Updated test cases for fixed AsciiQRCode logic --- QRCoderTests/AsciiQRCodeRendererTests.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/QRCoderTests/AsciiQRCodeRendererTests.cs b/QRCoderTests/AsciiQRCodeRendererTests.cs index 7ac2656b..b74bee07 100644 --- a/QRCoderTests/AsciiQRCodeRendererTests.cs +++ b/QRCoderTests/AsciiQRCodeRendererTests.cs @@ -14,8 +14,8 @@ public class AsciiQRCodeRendererTests [Category("QRRenderer/AsciiQRCode")] public void can_render_ascii_qrcode() { - var targetCode = " \n \n \n \n ██████████████ ██ ██ ██████████████ \n ██ ██ ██ ████ ██ ██ \n ██ ██████ ██ ██ ██ ██ ██ ██████ ██ \n ██ ██████ ██ ██ ██ ██████ ██ \n ██ ██████ ██ ██ ██ ██████ ██ \n ██ ██ ████████ ██ ██ \n ██████████████ ██ ██ ██ ██████████████ \n ██ ████ \n ██████████ ████ ████████ ██ ████ \n ████ ██ ██ ████ ████████ ██ \n ██ ██ ██████████ ██ ██ ██ ████ \n ██ ██ ████ ████ ████ \n ████████ ██████ ████ ██ ██ \n ████████ \n ██████████████ ████ ████ ██ ████ ████ \n ██ ██ ████████ \n ██ ██████ ██ ██ ██ ██ ██ ██ ██ \n ██ ██████ ██ ██████ ██ ██ \n ██ ██████ ██ ██ ██ ██ ██ ████ ████ \n ██ ██ ████ ████ ██ ██ \n ██████████████ ██████ ██ ██████ \n \n \n \n "; - + var targetCode = " \n \n \n \n ██████████████ ████ ██ ██████████████ \n ██ ██ ████ ██ ██ ██ \n ██ ██████ ██ ██ ██ ██ ██ ██████ ██ \n ██ ██████ ██ ██ ██ ██ ██████ ██ \n ██ ██████ ██ ██████████ ██ ██████ ██ \n ██ ██ ██ ██ \n ██████████████ ██ ██ ██ ██████████████ \n ██████████ \n ████ ██ ████ ██████ ██ ██████████ \n ██ ██ ██ ██ ██ ████ \n ████ ██████ ██████ ██████ ██ \n ████ ██ ██████ ██ ██ ██ \n ████ ████ ██ ██ ██ ██ ████ \n ██ ██ ██ ██ ██ \n ██████████████ ██ ████ ██████ ██ \n ██ ██ ██ ████ ██████ \n ██ ██████ ██ ██████ ████████ ██ ██ \n ██ ██████ ██ ██ ██ ████ \n ██ ██████ ██ ██████ ██ ██ ██ \n ██ ██ ██ ██ ██ ██████ \n ██████████████ ██ ██ ██ ██ ██ ██ \n \n \n \n "; + //Create QR code var gen = new QRCodeGenerator(); var data = gen.CreateQrCode("A05", QRCodeGenerator.ECCLevel.Q); @@ -28,8 +28,8 @@ public void can_render_ascii_qrcode() [Category("QRRenderer/AsciiQRCode")] public void can_render_ascii_qrcode_without_quietzones() { - var targetCode = "██████████████ ██ ██ ██████████████\n██ ██ ██ ████ ██ ██\n██ ██████ ██ ██ ██ ██ ██ ██████ ██\n██ ██████ ██ ██ ██ ██████ ██\n██ ██████ ██ ██ ██ ██████ ██\n██ ██ ████████ ██ ██\n██████████████ ██ ██ ██ ██████████████\n ██ ████ \n██████████ ████ ████████ ██ ████ \n████ ██ ██ ████ ████████ ██\n ██ ██ ██████████ ██ ██ ██ ████ \n██ ██ ████ ████ ████ \n ████████ ██████ ████ ██ ██\n ████████ \n██████████████ ████ ████ ██ ████ ████\n██ ██ ████████ \n██ ██████ ██ ██ ██ ██ ██ ██ ██\n██ ██████ ██ ██████ ██ ██ \n██ ██████ ██ ██ ██ ██ ██ ████ ████\n██ ██ ████ ████ ██ ██ \n██████████████ ██████ ██ ██████"; - + var targetCode = "██████████████ ████ ██ ██████████████\n██ ██ ████ ██ ██ ██\n██ ██████ ██ ██ ██ ██ ██ ██████ ██\n██ ██████ ██ ██ ██ ██ ██████ ██\n██ ██████ ██ ██████████ ██ ██████ ██\n██ ██ ██ ██\n██████████████ ██ ██ ██ ██████████████\n ██████████ \n ████ ██ ████ ██████ ██ ██████████\n██ ██ ██ ██ ██ ████\n ████ ██████ ██████ ██████ ██\n████ ██ ██████ ██ ██ ██ \n ████ ████ ██ ██ ██ ██ ████ \n ██ ██ ██ ██ ██ \n██████████████ ██ ████ ██████ ██ \n██ ██ ██ ████ ██████ \n██ ██████ ██ ██████ ████████ ██ ██\n██ ██████ ██ ██ ██ ████ \n██ ██████ ██ ██████ ██ ██ ██\n██ ██ ██ ██ ██ ██████\n██████████████ ██ ██ ██ ██ ██ ██"; + //Create QR code var gen = new QRCodeGenerator(); var data = gen.CreateQrCode("A05", QRCodeGenerator.ECCLevel.Q); @@ -42,7 +42,7 @@ public void can_render_ascii_qrcode_without_quietzones() [Category("QRRenderer/AsciiQRCode")] public void can_render_ascii_qrcode_with_custom_symbols() { - var targetCode = " \n \n \n \n \n \n \n \n XXXXXXXXXXXXXX XXXX XXXXXXXXXXXXXX \n XXXXXXXXXXXXXX XXXX XXXXXXXXXXXXXX \n XX XX XXXXXX XX XX XX \n XX XX XXXXXX XX XX XX \n XX XXXXXX XX XXXXXXXX XX XXXXXX XX \n XX XXXXXX XX XXXXXXXX XX XXXXXX XX \n XX XXXXXX XX XXXX XX XXXXXX XX \n XX XXXXXX XX XXXX XX XXXXXX XX \n XX XXXXXX XX XX XX XX XXXXXX XX \n XX XXXXXX XX XX XX XX XXXXXX XX \n XX XX XX XX XX \n XX XX XX XX XX \n XXXXXXXXXXXXXX XX XX XX XXXXXXXXXXXXXX \n XXXXXXXXXXXXXX XX XX XX XXXXXXXXXXXXXX \n XXXXXXXX \n XXXXXXXX \n XX XXXXXX XXXXXX XX XX XX \n XX XXXXXX XXXXXX XX XX XX \n XX XXXXXX XXXX XXXXXXXX XXXXXX XX \n XX XXXXXX XXXX XXXXXXXX XXXXXX XX \n XX XX XX XX XX XX \n XX XX XX XX XX XX \n XX XX XX XX XXXXXX \n XX XX XX XX XXXXXX \n XX XXXXXXXX XXXX XX XXXXXXXX XX \n XX XXXXXXXX XXXX XX XXXXXXXX XX \n XX XXXXXXXX XXXX \n XX XXXXXXXX XXXX \n XXXXXXXXXXXXXX XXXXXXXX XX XXXXXX \n XXXXXXXXXXXXXX XXXXXXXX XX XXXXXX \n XX XX XXXXXX XXXXXXXX \n XX XX XXXXXX XXXXXXXX \n XX XXXXXX XX XX XXXX XX XXXX \n XX XXXXXX XX XX XXXX XX XXXX \n XX XXXXXX XX XXXX XXXXXXXX \n XX XXXXXX XX XXXX XXXXXXXX \n XX XXXXXX XX XX XXXXXXXX XX XXXXXX \n XX XXXXXX XX XX XXXXXXXX XX XXXXXX \n XX XX XX XXXX XX \n XX XX XX XXXX XX \n XXXXXXXXXXXXXX XX XXXXXX XXXX XXXX \n XXXXXXXXXXXXXX XX XXXXXX XXXX XXXX \n \n \n \n \n \n \n \n "; + var targetCode = " \n \n \n \n \n \n \n \n XXXXXXXXXXXXXX XX XXXXXXXXXXXXXX \n XXXXXXXXXXXXXX XX XXXXXXXXXXXXXX \n XX XX XXXX XX XX \n XX XX XXXX XX XX \n XX XXXXXX XX XXXX XX XXXXXX XX \n XX XXXXXX XX XXXX XX XXXXXX XX \n XX XXXXXX XX XX XX XX XXXXXX XX \n XX XXXXXX XX XX XX XX XXXXXX XX \n XX XXXXXX XX XXXX XX XX XXXXXX XX \n XX XXXXXX XX XXXX XX XX XXXXXX XX \n XX XX XX XX XX XX \n XX XX XX XX XX XX \n XXXXXXXXXXXXXX XX XX XX XXXXXXXXXXXXXX \n XXXXXXXXXXXXXX XX XX XX XXXXXXXXXXXXXX \n XX XX \n XX XX \n XX XX XX XXXXXX XXXX XXXX XX \n XX XX XX XXXXXX XXXX XXXX XX \n XXXXXX XX XXXX XX XX XX XXXX \n XXXXXX XX XXXX XX XX XX XXXX \n XXXXXX XXXXXXXXXX XXXXXXXXXX \n XXXXXX XXXXXXXXXX XXXXXXXXXX \n XX XX XX XX XX XXXXXX XX XX \n XX XX XX XX XX XXXXXX XX XX \n XXXXXX XXXX XX XX XXXX XX XX \n XXXXXX XXXX XX XX XXXX XX XX \n XXXXXX XXXX XX XX \n XXXXXX XXXX XX XX \n XXXXXXXXXXXXXX XXXXXX XX \n XXXXXXXXXXXXXX XXXXXX XX \n XX XX XX XX XX \n XX XX XX XX XX \n XX XXXXXX XX XXXXXXXXXX XXXXXXXXXXXXXX \n XX XXXXXX XX XXXXXXXXXX XXXXXXXXXXXXXX \n XX XXXXXX XX XX XXXX XX XX XXXX \n XX XXXXXX XX XX XXXX XX XX XXXX \n XX XXXXXX XX XXXXXX XXXXXXXXXX \n XX XXXXXX XX XXXXXX XXXXXXXXXX \n XX XX XX XXXX XX XX XX \n XX XX XX XXXX XX XX XX \n XXXXXXXXXXXXXX XX XXXXXX XXXXXX \n XXXXXXXXXXXXXX XX XXXXXX XXXXXX \n \n \n \n \n \n \n \n "; //Create QR code var gen = new QRCodeGenerator(); @@ -65,7 +65,7 @@ public void can_instantate_parameterless() [Category("QRRenderer/AsciiQRCode")] public void can_render_ascii_qrcode_from_helper() { - var targetCode = " \n \n \n \n \n \n \n \n XXXXXXXXXXXXXX XXXX XXXXXXXXXXXXXX \n XXXXXXXXXXXXXX XXXX XXXXXXXXXXXXXX \n XX XX XXXXXX XX XX XX \n XX XX XXXXXX XX XX XX \n XX XXXXXX XX XXXXXXXX XX XXXXXX XX \n XX XXXXXX XX XXXXXXXX XX XXXXXX XX \n XX XXXXXX XX XXXX XX XXXXXX XX \n XX XXXXXX XX XXXX XX XXXXXX XX \n XX XXXXXX XX XX XX XX XXXXXX XX \n XX XXXXXX XX XX XX XX XXXXXX XX \n XX XX XX XX XX \n XX XX XX XX XX \n XXXXXXXXXXXXXX XX XX XX XXXXXXXXXXXXXX \n XXXXXXXXXXXXXX XX XX XX XXXXXXXXXXXXXX \n XXXXXXXX \n XXXXXXXX \n XX XXXXXX XXXXXX XX XX XX \n XX XXXXXX XXXXXX XX XX XX \n XX XXXXXX XXXX XXXXXXXX XXXXXX XX \n XX XXXXXX XXXX XXXXXXXX XXXXXX XX \n XX XX XX XX XX XX \n XX XX XX XX XX XX \n XX XX XX XX XXXXXX \n XX XX XX XX XXXXXX \n XX XXXXXXXX XXXX XX XXXXXXXX XX \n XX XXXXXXXX XXXX XX XXXXXXXX XX \n XX XXXXXXXX XXXX \n XX XXXXXXXX XXXX \n XXXXXXXXXXXXXX XXXXXXXX XX XXXXXX \n XXXXXXXXXXXXXX XXXXXXXX XX XXXXXX \n XX XX XXXXXX XXXXXXXX \n XX XX XXXXXX XXXXXXXX \n XX XXXXXX XX XX XXXX XX XXXX \n XX XXXXXX XX XX XXXX XX XXXX \n XX XXXXXX XX XXXX XXXXXXXX \n XX XXXXXX XX XXXX XXXXXXXX \n XX XXXXXX XX XX XXXXXXXX XX XXXXXX \n XX XXXXXX XX XX XXXXXXXX XX XXXXXX \n XX XX XX XXXX XX \n XX XX XX XXXX XX \n XXXXXXXXXXXXXX XX XXXXXX XXXX XXXX \n XXXXXXXXXXXXXX XX XXXXXX XXXX XXXX \n \n \n \n \n \n \n \n "; + var targetCode = " \n \n \n \n \n \n \n \n XXXXXXXXXXXXXX XX XXXXXXXXXXXXXX \n XXXXXXXXXXXXXX XX XXXXXXXXXXXXXX \n XX XX XXXX XX XX \n XX XX XXXX XX XX \n XX XXXXXX XX XXXX XX XXXXXX XX \n XX XXXXXX XX XXXX XX XXXXXX XX \n XX XXXXXX XX XX XX XX XXXXXX XX \n XX XXXXXX XX XX XX XX XXXXXX XX \n XX XXXXXX XX XXXX XX XX XXXXXX XX \n XX XXXXXX XX XXXX XX XX XXXXXX XX \n XX XX XX XX XX XX \n XX XX XX XX XX XX \n XXXXXXXXXXXXXX XX XX XX XXXXXXXXXXXXXX \n XXXXXXXXXXXXXX XX XX XX XXXXXXXXXXXXXX \n XX XX \n XX XX \n XX XX XX XXXXXX XXXX XXXX XX \n XX XX XX XXXXXX XXXX XXXX XX \n XXXXXX XX XXXX XX XX XX XXXX \n XXXXXX XX XXXX XX XX XX XXXX \n XXXXXX XXXXXXXXXX XXXXXXXXXX \n XXXXXX XXXXXXXXXX XXXXXXXXXX \n XX XX XX XX XX XXXXXX XX XX \n XX XX XX XX XX XXXXXX XX XX \n XXXXXX XXXX XX XX XXXX XX XX \n XXXXXX XXXX XX XX XXXX XX XX \n XXXXXX XXXX XX XX \n XXXXXX XXXX XX XX \n XXXXXXXXXXXXXX XXXXXX XX \n XXXXXXXXXXXXXX XXXXXX XX \n XX XX XX XX XX \n XX XX XX XX XX \n XX XXXXXX XX XXXXXXXXXX XXXXXXXXXXXXXX \n XX XXXXXX XX XXXXXXXXXX XXXXXXXXXXXXXX \n XX XXXXXX XX XX XXXX XX XX XXXX \n XX XXXXXX XX XX XXXX XX XX XXXX \n XX XXXXXX XX XXXXXX XXXXXXXXXX \n XX XXXXXX XX XXXXXX XXXXXXXXXX \n XX XX XX XXXX XX XX XX \n XX XX XX XXXX XX XX XX \n XXXXXXXXXXXXXX XX XXXXXX XXXXXX \n XXXXXXXXXXXXXX XX XXXXXX XXXXXX \n \n \n \n \n \n \n \n "; //Create QR code var asciiCode = AsciiQRCodeHelper.GetQRCode("A", 2, "X", " ", QRCodeGenerator.ECCLevel.Q); From 50999a941fe30936bf4ae74c595cdda8066dcfe1 Mon Sep 17 00:00:00 2001 From: Michael H Date: Mon, 8 Apr 2024 10:53:28 -0400 Subject: [PATCH 18/20] Update QRCoder/PayloadGenerator.cs Co-authored-by: Shane Krueger --- QRCoder/PayloadGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QRCoder/PayloadGenerator.cs b/QRCoder/PayloadGenerator.cs index 4beafa1e..0b640d7a 100644 --- a/QRCoder/PayloadGenerator.cs +++ b/QRCoder/PayloadGenerator.cs @@ -311,7 +311,7 @@ public class Url : Payload private readonly string url; /// - /// Generates a link. If protocol not given, http protocol will be added. + /// Generates a link. If the protocol is not specified, the http protocol will be added. /// /// Link url target public Url(string url) From defde0e4cb9854d6142f00866f2bd1fbe803ef20 Mon Sep 17 00:00:00 2001 From: Shane32 Date: Sat, 13 Apr 2024 11:10:16 -0400 Subject: [PATCH 19/20] Add support for WPA2 --- QRCoder/PayloadGenerator.cs | 3 ++- QRCoderTests/PayloadGeneratorTests.cs | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/QRCoder/PayloadGenerator.cs b/QRCoder/PayloadGenerator.cs index 6275e5be..8137d7f3 100644 --- a/QRCoder/PayloadGenerator.cs +++ b/QRCoder/PayloadGenerator.cs @@ -53,7 +53,8 @@ public enum Authentication { WEP, WPA, - nopass + nopass, + WPA2 } } diff --git a/QRCoderTests/PayloadGeneratorTests.cs b/QRCoderTests/PayloadGeneratorTests.cs index f4406bb7..2527f2d8 100644 --- a/QRCoderTests/PayloadGeneratorTests.cs +++ b/QRCoderTests/PayloadGeneratorTests.cs @@ -317,6 +317,20 @@ public void wifi_should_build_wpa() generator.ToString().ShouldBe($"WIFI:T:WPA;S:MyWiFiSSID;P:7heP4assw0rd;;"); } + [Fact] + [Category("PayloadGenerator/WiFi")] + public void wifi_should_build_wpa2() + { + var ssid = "MyWiFiSSID"; + var password = "7heP4assw0rd"; + var authmode = PayloadGenerator.WiFi.Authentication.WPA2; + var hideSSID = false; + + var generator = new PayloadGenerator.WiFi(ssid, password, authmode, hideSSID); + + generator.ToString().ShouldBe($"WIFI:T:WPA2;S:MyWiFiSSID;P:7heP4assw0rd;;"); + } + [Fact] [Category("PayloadGenerator/WiFi")] From f74e547d98d50aba4328f1f22ef35f7a2ba120ac Mon Sep 17 00:00:00 2001 From: Shane32 Date: Sat, 13 Apr 2024 11:11:20 -0400 Subject: [PATCH 20/20] Update --- QRCoderTests/PayloadGeneratorTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/QRCoderTests/PayloadGeneratorTests.cs b/QRCoderTests/PayloadGeneratorTests.cs index 2527f2d8..8a9a2c72 100644 --- a/QRCoderTests/PayloadGeneratorTests.cs +++ b/QRCoderTests/PayloadGeneratorTests.cs @@ -331,7 +331,6 @@ public void wifi_should_build_wpa2() generator.ToString().ShouldBe($"WIFI:T:WPA2;S:MyWiFiSSID;P:7heP4assw0rd;;"); } - [Fact] [Category("PayloadGenerator/WiFi")] public void wifi_should_ignore_hiddenSSID_param()