From b8ba8c9b9013875e6161586a118c9b04471af3b9 Mon Sep 17 00:00:00 2001 From: Shane32 Date: Sat, 18 May 2024 17:40:42 -0400 Subject: [PATCH 1/5] ECC code mismatch --- QRCoder/PayloadGenerator.cs | 4 ++-- QRCoder/QRCodeGenerator.cs | 4 +++- .../QRCoder.approved.txt | 4 ++-- QRCoderApiTests/net60-windows/QRCoder.approved.txt | 4 ++-- QRCoderApiTests/net60/QRCoder.approved.txt | 4 ++-- QRCoderApiTests/netstandard13/QRCoder.approved.txt | 4 ++-- 6 files changed, 13 insertions(+), 11 deletions(-) diff --git a/QRCoder/PayloadGenerator.cs b/QRCoder/PayloadGenerator.cs index 39bae5f0..0a143b02 100644 --- a/QRCoder/PayloadGenerator.cs +++ b/QRCoder/PayloadGenerator.cs @@ -15,7 +15,7 @@ public static class PayloadGenerator public abstract class Payload { public virtual int Version { get { return -1; } } - public virtual QRCodeGenerator.ECCLevel EccLevel { get { return QRCodeGenerator.ECCLevel.M; } } + public virtual QRCodeGenerator.ECCLevel? EccLevel { get { return null; } } // null is default public virtual QRCodeGenerator.EciMode EciMode { get { return QRCodeGenerator.EciMode.Default; } } public abstract override string ToString(); } @@ -2380,7 +2380,7 @@ public class SlovenianUpnQr : Payload private string _recipientSiReference = ""; public override int Version { get { return 15; } } - public override QRCodeGenerator.ECCLevel EccLevel { get { return QRCodeGenerator.ECCLevel.M; } } + public override QRCodeGenerator.ECCLevel? EccLevel { get { return QRCodeGenerator.ECCLevel.M; } } public override QRCodeGenerator.EciMode EciMode { get { return QRCodeGenerator.EciMode.Iso8859_2; } } private string LimitLength(string value, int maxLength) diff --git a/QRCoder/QRCodeGenerator.cs b/QRCoder/QRCodeGenerator.cs index 83dbc99a..64ea7e5b 100644 --- a/QRCoder/QRCodeGenerator.cs +++ b/QRCoder/QRCodeGenerator.cs @@ -93,7 +93,7 @@ public QRCodeData CreateQrCode(byte[] binaryData, ECCLevel eccLevel) /// Returns the raw QR code data which can be used for rendering. public static QRCodeData GenerateQrCode(PayloadGenerator.Payload payload) { - return GenerateQrCode(payload.ToString(), payload.EccLevel, false, false, payload.EciMode, payload.Version); + return GenerateQrCode(payload.ToString(), payload.EccLevel ?? ECCLevel.M, false, false, payload.EciMode, payload.Version); } /// @@ -105,6 +105,8 @@ public static QRCodeData GenerateQrCode(PayloadGenerator.Payload payload) /// Returns the raw QR code data which can be used for rendering. public static QRCodeData GenerateQrCode(PayloadGenerator.Payload payload, ECCLevel eccLevel) { + if (payload.EccLevel.HasValue && eccLevel != payload.EccLevel.Value) + throw new ArgumentException($"The provided payload requires a ECC level of {eccLevel}.", nameof(eccLevel)); return GenerateQrCode(payload.ToString(), eccLevel, false, false, payload.EciMode, payload.Version); } diff --git a/QRCoderApiTests/net35+net40+net50+net50-windows+netstandard20/QRCoder.approved.txt b/QRCoderApiTests/net35+net40+net50+net50-windows+netstandard20/QRCoder.approved.txt index 0573589b..a985a449 100644 --- a/QRCoderApiTests/net35+net40+net50+net50-windows+netstandard20/QRCoder.approved.txt +++ b/QRCoderApiTests/net35+net40+net50+net50-windows+netstandard20/QRCoder.approved.txt @@ -530,7 +530,7 @@ namespace QRCoder public abstract class Payload { protected Payload() { } - public virtual QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } + public virtual QRCoder.QRCodeGenerator.ECCLevel? EccLevel { get; } public virtual QRCoder.QRCodeGenerator.EciMode EciMode { get; } public virtual int Version { get; } public abstract override string ToString() { } @@ -697,7 +697,7 @@ namespace QRCoder { public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, string recipientSiModel = "SI00", string recipientSiReference = "", string code = "OTHR") { } public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, System.DateTime? deadline, string recipientSiModel = "SI99", string recipientSiReference = "", string code = "OTHR") { } - public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } + public override QRCoder.QRCodeGenerator.ECCLevel? EccLevel { get; } public override QRCoder.QRCodeGenerator.EciMode EciMode { get; } public override int Version { get; } public override string ToString() { } diff --git a/QRCoderApiTests/net60-windows/QRCoder.approved.txt b/QRCoderApiTests/net60-windows/QRCoder.approved.txt index 3f03e15b..b7b026f7 100644 --- a/QRCoderApiTests/net60-windows/QRCoder.approved.txt +++ b/QRCoderApiTests/net60-windows/QRCoder.approved.txt @@ -535,7 +535,7 @@ namespace QRCoder public abstract class Payload { protected Payload() { } - public virtual QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } + public virtual QRCoder.QRCodeGenerator.ECCLevel? EccLevel { get; } public virtual QRCoder.QRCodeGenerator.EciMode EciMode { get; } public virtual int Version { get; } public abstract override string ToString() { } @@ -702,7 +702,7 @@ namespace QRCoder { public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, string recipientSiModel = "SI00", string recipientSiReference = "", string code = "OTHR") { } public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, System.DateTime? deadline, string recipientSiModel = "SI99", string recipientSiReference = "", string code = "OTHR") { } - public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } + public override QRCoder.QRCodeGenerator.ECCLevel? EccLevel { get; } public override QRCoder.QRCodeGenerator.EciMode EciMode { get; } public override int Version { get; } public override string ToString() { } diff --git a/QRCoderApiTests/net60/QRCoder.approved.txt b/QRCoderApiTests/net60/QRCoder.approved.txt index 7b3c4ef1..04568e88 100644 --- a/QRCoderApiTests/net60/QRCoder.approved.txt +++ b/QRCoderApiTests/net60/QRCoder.approved.txt @@ -493,7 +493,7 @@ namespace QRCoder public abstract class Payload { protected Payload() { } - public virtual QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } + public virtual QRCoder.QRCodeGenerator.ECCLevel? EccLevel { get; } public virtual QRCoder.QRCodeGenerator.EciMode EciMode { get; } public virtual int Version { get; } public abstract override string ToString() { } @@ -660,7 +660,7 @@ namespace QRCoder { public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, string recipientSiModel = "SI00", string recipientSiReference = "", string code = "OTHR") { } public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, System.DateTime? deadline, string recipientSiModel = "SI99", string recipientSiReference = "", string code = "OTHR") { } - public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } + public override QRCoder.QRCodeGenerator.ECCLevel? EccLevel { get; } public override QRCoder.QRCodeGenerator.EciMode EciMode { get; } public override int Version { get; } public override string ToString() { } diff --git a/QRCoderApiTests/netstandard13/QRCoder.approved.txt b/QRCoderApiTests/netstandard13/QRCoder.approved.txt index 311ba68f..c2701328 100644 --- a/QRCoderApiTests/netstandard13/QRCoder.approved.txt +++ b/QRCoderApiTests/netstandard13/QRCoder.approved.txt @@ -473,7 +473,7 @@ namespace QRCoder public abstract class Payload { protected Payload() { } - public virtual QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } + public virtual QRCoder.QRCodeGenerator.ECCLevel? EccLevel { get; } public virtual QRCoder.QRCodeGenerator.EciMode EciMode { get; } public virtual int Version { get; } public abstract override string ToString() { } @@ -640,7 +640,7 @@ namespace QRCoder { public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, string recipientSiModel = "SI00", string recipientSiReference = "", string code = "OTHR") { } public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, System.DateTime? deadline, string recipientSiModel = "SI99", string recipientSiReference = "", string code = "OTHR") { } - public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } + public override QRCoder.QRCodeGenerator.ECCLevel? EccLevel { get; } public override QRCoder.QRCodeGenerator.EciMode EciMode { get; } public override int Version { get; } public override string ToString() { } From 4ca3ec9838e8f4d8e5570c8f5f3ab79f813d535f Mon Sep 17 00:00:00 2001 From: Shane32 Date: Sun, 19 May 2024 09:51:04 -0400 Subject: [PATCH 2/5] Add tests --- QRCoder/PayloadGenerator.cs | 4 +- QRCoder/QRCodeGenerator.ECCLevel.cs | 14 ++++-- QRCoder/QRCodeGenerator.cs | 32 +++++++++++-- QRCoderTests/QRGeneratorTests.cs | 73 +++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+), 10 deletions(-) diff --git a/QRCoder/PayloadGenerator.cs b/QRCoder/PayloadGenerator.cs index 0a143b02..8682d0f0 100644 --- a/QRCoder/PayloadGenerator.cs +++ b/QRCoder/PayloadGenerator.cs @@ -15,7 +15,7 @@ public static class PayloadGenerator public abstract class Payload { public virtual int Version { get { return -1; } } - public virtual QRCodeGenerator.ECCLevel? EccLevel { get { return null; } } // null is default + public virtual QRCodeGenerator.ECCLevel EccLevel { get { return QRCodeGenerator.ECCLevel.Default; } } // null is default public virtual QRCodeGenerator.EciMode EciMode { get { return QRCodeGenerator.EciMode.Default; } } public abstract override string ToString(); } @@ -2380,7 +2380,7 @@ public class SlovenianUpnQr : Payload private string _recipientSiReference = ""; public override int Version { get { return 15; } } - public override QRCodeGenerator.ECCLevel? EccLevel { get { return QRCodeGenerator.ECCLevel.M; } } + public override QRCodeGenerator.ECCLevel EccLevel { get { return QRCodeGenerator.ECCLevel.M; } } public override QRCodeGenerator.EciMode EciMode { get { return QRCodeGenerator.EciMode.Iso8859_2; } } private string LimitLength(string value, int maxLength) diff --git a/QRCoder/QRCodeGenerator.ECCLevel.cs b/QRCoder/QRCodeGenerator.ECCLevel.cs index aedfa3c9..d8a0ad57 100644 --- a/QRCoder/QRCodeGenerator.ECCLevel.cs +++ b/QRCoder/QRCodeGenerator.ECCLevel.cs @@ -8,29 +8,35 @@ public partial class QRCodeGenerator /// public enum ECCLevel { + /// + /// Default error correction level, which will select Level M (Medium) unless otherwise specified by the payload. + /// Level M allows approximately 15% of data to be recovered, offering a balance between data capacity and error recovery. + /// + Default = -1, + /// /// Level L: Low error correction (approximately 7% of data can be recovered). /// This level allows the highest data density. /// - L, + L = 0, /// /// Level M: Medium error correction (approximately 15% of data can be recovered). /// Offers a balance between data capacity and error recovery. /// - M, + M = 1, /// /// Level Q: Quartile error correction (approximately 25% of data can be recovered). /// More robust error correction at the cost of reduced data capacity. /// - Q, + Q = 2, /// /// Level H: High error correction (approximately 30% of data can be recovered). /// Provides the highest level of error recovery, ideal for environments with high risk of data loss. /// - H + H = 3 } } } diff --git a/QRCoder/QRCodeGenerator.cs b/QRCoder/QRCodeGenerator.cs index 64ea7e5b..7f52921a 100644 --- a/QRCoder/QRCodeGenerator.cs +++ b/QRCoder/QRCodeGenerator.cs @@ -93,7 +93,7 @@ public QRCodeData CreateQrCode(byte[] binaryData, ECCLevel eccLevel) /// Returns the raw QR code data which can be used for rendering. public static QRCodeData GenerateQrCode(PayloadGenerator.Payload payload) { - return GenerateQrCode(payload.ToString(), payload.EccLevel ?? ECCLevel.M, false, false, payload.EciMode, payload.Version); + return GenerateQrCode(payload.ToString(), payload.EccLevel, false, false, payload.EciMode, payload.Version); } /// @@ -105,8 +105,10 @@ public static QRCodeData GenerateQrCode(PayloadGenerator.Payload payload) /// Returns the raw QR code data which can be used for rendering. public static QRCodeData GenerateQrCode(PayloadGenerator.Payload payload, ECCLevel eccLevel) { - if (payload.EccLevel.HasValue && eccLevel != payload.EccLevel.Value) - throw new ArgumentException($"The provided payload requires a ECC level of {eccLevel}.", nameof(eccLevel)); + if (eccLevel == ECCLevel.Default) + eccLevel = payload.EccLevel; + else if (payload.EccLevel != ECCLevel.Default && eccLevel != payload.EccLevel) + throw new ArgumentOutOfRangeException(nameof(eccLevel), $"The provided payload requires a ECC level of {eccLevel}."); return GenerateQrCode(payload.ToString(), eccLevel, false, false, payload.EciMode, payload.Version); } @@ -123,6 +125,7 @@ public static QRCodeData GenerateQrCode(PayloadGenerator.Payload payload, ECCLev /// Returns the raw QR code data which can be used for rendering. public static QRCodeData GenerateQrCode(string plainText, ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, EciMode eciMode = EciMode.Default, int requestedVersion = -1) { + eccLevel = ValidateECCLevel(eccLevel); EncodingMode encoding = GetEncodingFromPlaintext(plainText, forceUtf8); var codedText = PlainTextToBinary(plainText, encoding, eciMode, utf8BOM, forceUtf8); var dataInputLength = GetDataLength(encoding, plainText, codedText, forceUtf8); @@ -167,7 +170,6 @@ public static QRCodeData GenerateQrCode(string plainText, ECCLevel eccLevel, boo return GenerateQrCode(completeBitArray, eccLevel, version); } - /// /// Calculates the QR code data which than can be used in one of the rendering classes to generate a graphical representation. /// @@ -177,6 +179,7 @@ public static QRCodeData GenerateQrCode(string plainText, ECCLevel eccLevel, boo /// Returns the raw QR code data which can be used for rendering. public static QRCodeData GenerateQrCode(byte[] binaryData, ECCLevel eccLevel) { + eccLevel = ValidateECCLevel(eccLevel); int version = GetVersion(binaryData.Length, EncodingMode.Byte, eccLevel); int countIndicatorLen = GetCountIndicatorLength(version, EncodingMode.Byte); @@ -189,6 +192,27 @@ public static QRCodeData GenerateQrCode(byte[] binaryData, ECCLevel eccLevel) return GenerateQrCode(bitArray, eccLevel, version); } + /// + /// Validates the specified error correction level. + /// Returns the provided level if it is valid, or the level M if the provided level is Default. + /// Throws an exception if an invalid level is provided. + /// + private static ECCLevel ValidateECCLevel(ECCLevel eccLevel) + { + switch (eccLevel) + { + case ECCLevel.L: + case ECCLevel.M: + case ECCLevel.Q: + case ECCLevel.H: + return eccLevel; + case ECCLevel.Default: + return ECCLevel.M; + default: + throw new ArgumentOutOfRangeException(nameof(eccLevel), eccLevel, "Invalid error correction level."); + } + } + private static readonly BitArray _repeatingPattern = new BitArray( new[] { true, true, true, false, true, true, false, false, false, false, false, true, false, false, false, true }); diff --git a/QRCoderTests/QRGeneratorTests.cs b/QRCoderTests/QRGeneratorTests.cs index 02b678ab..87b61fec 100644 --- a/QRCoderTests/QRGeneratorTests.cs +++ b/QRCoderTests/QRGeneratorTests.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Collections; using System.Text; +using System; namespace QRCoderTests { @@ -226,6 +227,78 @@ bool IsValidISO(string input) } } } + + [Fact] + [Category("QRGenerator/EccLevel")] + public void ecc_level_from_payload_works() + { + var stringValue = "this is a test"; + + // set up baselines + var expectedL = Encode(QRCodeGenerator.GenerateQrCode(stringValue, QRCodeGenerator.ECCLevel.L)); + var expectedM = Encode(QRCodeGenerator.GenerateQrCode(stringValue, QRCodeGenerator.ECCLevel.M)); + var expectedQ = Encode(QRCodeGenerator.GenerateQrCode(stringValue, QRCodeGenerator.ECCLevel.Q)); + var expectedH = Encode(QRCodeGenerator.GenerateQrCode(stringValue, QRCodeGenerator.ECCLevel.H)); + + // ensure that the baselines are different from each other + expectedL.ShouldNotBe(expectedM); + expectedL.ShouldNotBe(expectedQ); + expectedL.ShouldNotBe(expectedH); + expectedM.ShouldNotBe(expectedQ); + expectedM.ShouldNotBe(expectedH); + expectedQ.ShouldNotBe(expectedH); + + // validate that any ECC level can be used when the payload specifies a default ECC level + var payloadDefault = new SamplePayload(stringValue, QRCodeGenerator.ECCLevel.Default); + Encode(QRCodeGenerator.GenerateQrCode(payloadDefault)).ShouldBe(expectedM); + Encode(QRCodeGenerator.GenerateQrCode(payloadDefault, QRCodeGenerator.ECCLevel.Default)).ShouldBe(expectedM); + Encode(QRCodeGenerator.GenerateQrCode(payloadDefault, QRCodeGenerator.ECCLevel.L)).ShouldBe(expectedL); + Encode(QRCodeGenerator.GenerateQrCode(payloadDefault, QRCodeGenerator.ECCLevel.M)).ShouldBe(expectedM); + Encode(QRCodeGenerator.GenerateQrCode(payloadDefault, QRCodeGenerator.ECCLevel.Q)).ShouldBe(expectedQ); + Encode(QRCodeGenerator.GenerateQrCode(payloadDefault, QRCodeGenerator.ECCLevel.H)).ShouldBe(expectedH); + + // validate that the ECC level specified in the payload is used when default is specified, + // or checks that the selected ECC level matches the payload ECC level, throwing an exception otherwise + Verify(QRCodeGenerator.ECCLevel.L, expectedL); + Verify(QRCodeGenerator.ECCLevel.M, expectedM); + Verify(QRCodeGenerator.ECCLevel.Q, expectedQ); + Verify(QRCodeGenerator.ECCLevel.H, expectedH); + + + void Verify(QRCodeGenerator.ECCLevel eccLevel, string expected) + { + var payload = new SamplePayload(stringValue, eccLevel); + Encode(QRCodeGenerator.GenerateQrCode(payload)).ShouldBe(expected); + foreach (var ecc in Enum.GetValues(typeof(QRCodeGenerator.ECCLevel)).Cast()) + { + if (ecc == eccLevel || ecc == QRCodeGenerator.ECCLevel.Default) + Encode(QRCodeGenerator.GenerateQrCode(payload, ecc)).ShouldBe(expected); + else + Should.Throw(() => Encode(QRCodeGenerator.GenerateQrCode(payload, ecc))); + } + } + + string Encode(QRCodeData qrData) + { + return string.Join("", qrData.ModuleMatrix.Select(x => x.ToBitString()).ToArray()); + } + } + + private class SamplePayload : PayloadGenerator.Payload + { + private string _data; + private QRCodeGenerator.ECCLevel _eccLevel; + + public SamplePayload(string data, QRCodeGenerator.ECCLevel eccLevel) + { + _data = data; + _eccLevel = eccLevel; + } + + public override QRCodeGenerator.ECCLevel EccLevel => _eccLevel; + + public override string ToString() => _data; + } } public static class ExtensionMethods From 94e4cfeb248ca889895cce3efdb4408fd53b3987 Mon Sep 17 00:00:00 2001 From: Shane32 Date: Sun, 19 May 2024 09:58:02 -0400 Subject: [PATCH 3/5] Update API approvals --- .../QRCoder.approved.txt | 5 +++-- QRCoderApiTests/net60-windows/QRCoder.approved.txt | 5 +++-- QRCoderApiTests/net60/QRCoder.approved.txt | 5 +++-- QRCoderApiTests/netstandard13/QRCoder.approved.txt | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/QRCoderApiTests/net35+net40+net50+net50-windows+netstandard20/QRCoder.approved.txt b/QRCoderApiTests/net35+net40+net50+net50-windows+netstandard20/QRCoder.approved.txt index a985a449..60b1ecc2 100644 --- a/QRCoderApiTests/net35+net40+net50+net50-windows+netstandard20/QRCoder.approved.txt +++ b/QRCoderApiTests/net35+net40+net50+net50-windows+netstandard20/QRCoder.approved.txt @@ -530,7 +530,7 @@ namespace QRCoder public abstract class Payload { protected Payload() { } - public virtual QRCoder.QRCodeGenerator.ECCLevel? EccLevel { get; } + public virtual QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } public virtual QRCoder.QRCodeGenerator.EciMode EciMode { get; } public virtual int Version { get; } public abstract override string ToString() { } @@ -697,7 +697,7 @@ namespace QRCoder { public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, string recipientSiModel = "SI00", string recipientSiReference = "", string code = "OTHR") { } public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, System.DateTime? deadline, string recipientSiModel = "SI99", string recipientSiReference = "", string code = "OTHR") { } - public override QRCoder.QRCodeGenerator.ECCLevel? EccLevel { get; } + public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } public override QRCoder.QRCodeGenerator.EciMode EciMode { get; } public override int Version { get; } public override string ToString() { } @@ -895,6 +895,7 @@ namespace QRCoder public static QRCoder.QRCodeData GenerateQrCode(string plainText, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1) { } public enum ECCLevel { + Default = -1, L = 0, M = 1, Q = 2, diff --git a/QRCoderApiTests/net60-windows/QRCoder.approved.txt b/QRCoderApiTests/net60-windows/QRCoder.approved.txt index b7b026f7..ff07d0df 100644 --- a/QRCoderApiTests/net60-windows/QRCoder.approved.txt +++ b/QRCoderApiTests/net60-windows/QRCoder.approved.txt @@ -535,7 +535,7 @@ namespace QRCoder public abstract class Payload { protected Payload() { } - public virtual QRCoder.QRCodeGenerator.ECCLevel? EccLevel { get; } + public virtual QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } public virtual QRCoder.QRCodeGenerator.EciMode EciMode { get; } public virtual int Version { get; } public abstract override string ToString() { } @@ -702,7 +702,7 @@ namespace QRCoder { public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, string recipientSiModel = "SI00", string recipientSiReference = "", string code = "OTHR") { } public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, System.DateTime? deadline, string recipientSiModel = "SI99", string recipientSiReference = "", string code = "OTHR") { } - public override QRCoder.QRCodeGenerator.ECCLevel? EccLevel { get; } + public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } public override QRCoder.QRCodeGenerator.EciMode EciMode { get; } public override int Version { get; } public override string ToString() { } @@ -903,6 +903,7 @@ namespace QRCoder public static QRCoder.QRCodeData GenerateQrCode(string plainText, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1) { } public enum ECCLevel { + Default = -1, L = 0, M = 1, Q = 2, diff --git a/QRCoderApiTests/net60/QRCoder.approved.txt b/QRCoderApiTests/net60/QRCoder.approved.txt index 04568e88..e558ea6f 100644 --- a/QRCoderApiTests/net60/QRCoder.approved.txt +++ b/QRCoderApiTests/net60/QRCoder.approved.txt @@ -493,7 +493,7 @@ namespace QRCoder public abstract class Payload { protected Payload() { } - public virtual QRCoder.QRCodeGenerator.ECCLevel? EccLevel { get; } + public virtual QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } public virtual QRCoder.QRCodeGenerator.EciMode EciMode { get; } public virtual int Version { get; } public abstract override string ToString() { } @@ -660,7 +660,7 @@ namespace QRCoder { public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, string recipientSiModel = "SI00", string recipientSiReference = "", string code = "OTHR") { } public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, System.DateTime? deadline, string recipientSiModel = "SI99", string recipientSiReference = "", string code = "OTHR") { } - public override QRCoder.QRCodeGenerator.ECCLevel? EccLevel { get; } + public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } public override QRCoder.QRCodeGenerator.EciMode EciMode { get; } public override int Version { get; } public override string ToString() { } @@ -837,6 +837,7 @@ namespace QRCoder public static QRCoder.QRCodeData GenerateQrCode(string plainText, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1) { } public enum ECCLevel { + Default = -1, L = 0, M = 1, Q = 2, diff --git a/QRCoderApiTests/netstandard13/QRCoder.approved.txt b/QRCoderApiTests/netstandard13/QRCoder.approved.txt index c2701328..34362e64 100644 --- a/QRCoderApiTests/netstandard13/QRCoder.approved.txt +++ b/QRCoderApiTests/netstandard13/QRCoder.approved.txt @@ -473,7 +473,7 @@ namespace QRCoder public abstract class Payload { protected Payload() { } - public virtual QRCoder.QRCodeGenerator.ECCLevel? EccLevel { get; } + public virtual QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } public virtual QRCoder.QRCodeGenerator.EciMode EciMode { get; } public virtual int Version { get; } public abstract override string ToString() { } @@ -640,7 +640,7 @@ namespace QRCoder { public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, string recipientSiModel = "SI00", string recipientSiReference = "", string code = "OTHR") { } public SlovenianUpnQr(string payerName, string payerAddress, string payerPlace, string recipientName, string recipientAddress, string recipientPlace, string recipientIban, string description, double amount, System.DateTime? deadline, string recipientSiModel = "SI99", string recipientSiReference = "", string code = "OTHR") { } - public override QRCoder.QRCodeGenerator.ECCLevel? EccLevel { get; } + public override QRCoder.QRCodeGenerator.ECCLevel EccLevel { get; } public override QRCoder.QRCodeGenerator.EciMode EciMode { get; } public override int Version { get; } public override string ToString() { } @@ -802,6 +802,7 @@ namespace QRCoder public static QRCoder.QRCodeData GenerateQrCode(string plainText, QRCoder.QRCodeGenerator.ECCLevel eccLevel, bool forceUtf8 = false, bool utf8BOM = false, QRCoder.QRCodeGenerator.EciMode eciMode = 0, int requestedVersion = -1) { } public enum ECCLevel { + Default = -1, L = 0, M = 1, Q = 2, From d65a5f0c0b4531ca01fd72eca9cb8008174df662 Mon Sep 17 00:00:00 2001 From: Raffael Herrmann Date: Sun, 19 May 2024 23:28:45 +0200 Subject: [PATCH 4/5] Update QRCoder/PayloadGenerator.cs --- QRCoder/PayloadGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QRCoder/PayloadGenerator.cs b/QRCoder/PayloadGenerator.cs index 8682d0f0..b4b0fd76 100644 --- a/QRCoder/PayloadGenerator.cs +++ b/QRCoder/PayloadGenerator.cs @@ -15,7 +15,7 @@ public static class PayloadGenerator public abstract class Payload { public virtual int Version { get { return -1; } } - public virtual QRCodeGenerator.ECCLevel EccLevel { get { return QRCodeGenerator.ECCLevel.Default; } } // null is default + public virtual QRCodeGenerator.ECCLevel EccLevel { get { return QRCodeGenerator.ECCLevel.Default; } } public virtual QRCodeGenerator.EciMode EciMode { get { return QRCodeGenerator.EciMode.Default; } } public abstract override string ToString(); } From c732d19429d0e9e87c2cca577cf77bb282a196d5 Mon Sep 17 00:00:00 2001 From: Raffael Herrmann Date: Sun, 19 May 2024 23:49:28 +0200 Subject: [PATCH 5/5] Update QRCoderTests/QRGeneratorTests.cs --- QRCoderTests/QRGeneratorTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/QRCoderTests/QRGeneratorTests.cs b/QRCoderTests/QRGeneratorTests.cs index 41c37b0d..7015d66d 100644 --- a/QRCoderTests/QRGeneratorTests.cs +++ b/QRCoderTests/QRGeneratorTests.cs @@ -93,7 +93,7 @@ public void validate_antilogtable() [InlineData("ABCDEFGHIJKLMNOPQRSTUVWX", "C9LlmjRV+TPDkR03MlgDvo/DP+U", 29)] [InlineData("ABCDEFGHIJKLMNOPQRSTUVWXY", "+EtALGm0mrDrnZVW54WdXG612P0", 29)] [InlineData("ABCDEFGHIJKLMNOPQRSTUVWXYZ789012345", "3nFUvZ/Aa2wUdAj1zlMmSu9x4kU", 29)] - // versino 4 alphanumeric + // version 4 alphanumeric [InlineData("ABCDEFGHIJKLMNOPQRSTUVWXYZ7890123456", "9K6EinxynS2KRum46iQsVoPgM7k", 33)] // version 1 binary