Skip to content

Commit 9821317

Browse files
committed
fix code layout
1 parent 113a0bd commit 9821317

14 files changed

+206
-292
lines changed

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ csharp_style_prefer_utf8_string_literals = true:none
124124
# IDE0230: Use UTF-8 string literal
125125
dotnet_diagnostic.IDE0230.severity = none
126126

127+
# SA1200: Using directives should be placed correctly
128+
dotnet_diagnostic.SA1200.severity = none
129+
130+
# SA1008: Opening parenthesis should be spaced correctly
131+
dotnet_diagnostic.SA1008.severity = none
132+
133+
# SA1313: Parameter names should begin with lower-case letter
134+
dotnet_diagnostic.SA1313.severity = none
135+
127136
[*.vb]
128137
#### Naming styles ####
129138

SimpleBase.sln

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Global
3838
{617BA86D-31E2-41EA-A1C8-E37602D58C07}.Release|Any CPU.ActiveCfg = Release|Any CPU
3939
{617BA86D-31E2-41EA-A1C8-E37602D58C07}.Release|Any CPU.Build.0 = Release|Any CPU
4040
{83A36BC1-8195-4595-A59D-E6B66AD47B97}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
41+
{83A36BC1-8195-4595-A59D-E6B66AD47B97}.Debug|Any CPU.Build.0 = Debug|Any CPU
4142
{83A36BC1-8195-4595-A59D-E6B66AD47B97}.Release|Any CPU.ActiveCfg = Release|Any CPU
4243
{83A36BC1-8195-4595-A59D-E6B66AD47B97}.Release|Any CPU.Build.0 = Release|Any CPU
4344
EndGlobalSection

src/Base16.cs

+18-86
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
using System.IO;
99
using System.Threading.Tasks;
1010

11-
namespace SimpleBase
11+
namespace SimpleBase;
12+
13+
/// <summary>
14+
/// Base16 encoding/decoding.
15+
/// </summary>
16+
public sealed class Base16 : IBaseCoder, IBaseStreamCoder, INonAllocatingBaseCoder
1217
{
13-
/// <summary>
14-
/// Base16 encoding/decoding.
15-
/// </summary>
16-
public sealed class Base16 : IBaseEncoder, IBaseStreamEncoder, INonAllocatingBaseEncoder
17-
{
18-
private static readonly Lazy<Base16> upperCase = new (() => new Base16(Base16Alphabet.UpperCase));
19-
private static readonly Lazy<Base16> lowerCase = new (() => new Base16(Base16Alphabet.LowerCase));
20-
private static readonly Lazy<Base16> modHex = new (() => new Base16(Base16Alphabet.ModHex));
18+
private static readonly Lazy<Base16> upperCase = new (() => new Base16(Base16Alphabet.UpperCase));
19+
private static readonly Lazy<Base16> lowerCase = new (() => new Base16(Base16Alphabet.LowerCase));
20+
private static readonly Lazy<Base16> modHex = new (() => new Base16(Base16Alphabet.ModHex));
2121

2222
/// <summary>
2323
/// Initializes a new instance of the <see cref="Base16"/> class.
@@ -78,83 +78,15 @@ public int GetSafeCharCountForEncoding(ReadOnlySpan<byte> buffer)
7878
return buffer.Length * 2;
7979
}
8080

81-
/// <summary>
82-
/// Encode to Base16 representation using uppercase lettering.
83-
/// </summary>
84-
/// <param name="bytes">Bytes to encode.</param>
85-
/// <returns>Base16 string.</returns>
86-
[Obsolete("Deprecated. Use Base16.UpperCase.Encode() instead")]
87-
public static unsafe string EncodeUpper(ReadOnlySpan<byte> bytes)
88-
{
89-
return UpperCase.Encode(bytes);
90-
}
91-
92-
/// <summary>
93-
/// Encode to Base16 representation using lowercase lettering.
94-
/// </summary>
95-
/// <param name="bytes">Bytes to encode.</param>
96-
/// <returns>Base16 string.</returns>
97-
[Obsolete("Deprecated. Use Base16.LowerCase.Encode() instead")]
98-
public static unsafe string EncodeLower(ReadOnlySpan<byte> bytes)
99-
{
100-
return LowerCase.Encode(bytes);
101-
}
102-
103-
/// <summary>
104-
/// Encodes stream of bytes into a Base16 text.
105-
/// </summary>
106-
/// <param name="input">Stream that provides bytes to be encoded.</param>
107-
/// <param name="output">Stream that the encoded text is written to.</param>
108-
[Obsolete("Deprecated. Use Base16.UpperCase.Encode() instead")]
109-
public static void EncodeUpper(Stream input, TextWriter output)
110-
{
111-
UpperCase.Encode(input, output);
112-
}
113-
114-
/// <summary>
115-
/// Encodes stream of bytes into a Base16 text.
116-
/// </summary>
117-
/// <param name="input">Stream that provides bytes to be encoded.</param>
118-
/// <param name="output">Stream that the encoded text is written to.</param>
119-
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
120-
[Obsolete("Deprecated. Use Base16.UpperCase.EncodeAsync instead")]
121-
public static Task EncodeUpperAsync(Stream input, TextWriter output)
122-
{
123-
return UpperCase.EncodeAsync(input, output);
124-
}
125-
126-
/// <summary>
127-
/// Encodes stream of bytes into a Base16 text.
128-
/// </summary>
129-
/// <param name="input">Stream that provides bytes to be encoded.</param>
130-
/// <param name="output">Stream that the encoded text is written to.</param>
131-
[Obsolete("Deprecated. Use Base16.LowerCase.Encode() instead")]
132-
public static void EncodeLower(Stream input, TextWriter output)
133-
{
134-
LowerCase.Encode(input, output);
135-
}
136-
137-
/// <summary>
138-
/// Encodes stream of bytes into a Base16 text.
139-
/// </summary>
140-
/// <param name="input">Stream that provides bytes to be encoded.</param>
141-
/// <param name="output">Stream that the encoded text is written to.</param>
142-
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
143-
[Obsolete("Deprecated. Use Base16.LowerCase.EncodeLower instead")]
144-
public static Task EncodeLowerAsync(Stream input, TextWriter output)
145-
{
146-
return LowerCase.EncodeAsync(input, output);
147-
}
148-
149-
/// <summary>
150-
/// Decode Upper/Lowercase Base16 text into bytes.
151-
/// </summary>
152-
/// <param name="text">Hex string.</param>
153-
/// <returns>Decoded bytes.</returns>
154-
public static Span<byte> Decode(string text)
155-
{
156-
return UpperCase.Decode(text.AsSpan());
157-
}
81+
/// <summary>
82+
/// Decode Upper/Lowercase Base16 text into bytes.
83+
/// </summary>
84+
/// <param name="text">Hex string.</param>
85+
/// <returns>Decoded bytes.</returns>
86+
public static Span<byte> Decode(string text)
87+
{
88+
return UpperCase.Decode(text.AsSpan());
89+
}
15890

15991
/// <summary>
16092
/// Decode Base16 text through streams for generic use. Stream based variant tries to consume

src/Base16Alphabet.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ namespace SimpleBase;
1212
/// </summary>
1313
public class Base16Alphabet : CodingAlphabet
1414
{
15-
private static readonly Lazy<Base16Alphabet> upperCaseAlphabet = new(() => new Base16Alphabet("0123456789ABCDEF"));
15+
private static readonly Lazy<Base16Alphabet> upperCaseAlphabet = new (() => new Base16Alphabet("0123456789ABCDEF"));
1616

17-
private static readonly Lazy<Base16Alphabet> lowerCaseAlphabet = new(() => new Base16Alphabet("0123456789abcdef"));
17+
private static readonly Lazy<Base16Alphabet> lowerCaseAlphabet = new (() => new Base16Alphabet("0123456789abcdef"));
1818

19-
private static readonly Lazy<Base16Alphabet> modHexAlphabet = new(() => new Base16Alphabet("cbdefghijklnrtuv"));
19+
private static readonly Lazy<Base16Alphabet> modHexAlphabet = new (() => new Base16Alphabet("cbdefghijklnrtuv"));
2020

2121
/// <summary>
2222
/// Initializes a new instance of the <see cref="Base16Alphabet"/> class with

src/Base32.cs

+13-16
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ public sealed class Base32 : IBaseCoder, IBaseStreamCoder, INonAllocatingBaseCod
1818
private const int bitsPerByte = 8;
1919
private const int bitsPerChar = 5;
2020

21-
private static readonly Lazy<Base32> crockford = new(() => new Base32(Base32Alphabet.Crockford));
22-
private static readonly Lazy<Base32> rfc4648 = new(() => new Base32(Base32Alphabet.Rfc4648));
23-
private static readonly Lazy<Base32> extendedHex = new(() => new Base32(Base32Alphabet.ExtendedHex));
24-
private static readonly Lazy<Base32> zBase32 = new(() => new Base32(Base32Alphabet.ZBase32));
25-
private static readonly Lazy<Base32> geohash = new(() => new Base32(Base32Alphabet.Geohash));
26-
private static readonly Lazy<Base32> bech32 = new(() => new Base32(Base32Alphabet.Bech32));
21+
private static readonly Lazy<Base32> crockford = new (() => new Base32(Base32Alphabet.Crockford));
22+
private static readonly Lazy<Base32> rfc4648 = new (() => new Base32(Base32Alphabet.Rfc4648));
23+
private static readonly Lazy<Base32> extendedHex = new (() => new Base32(Base32Alphabet.ExtendedHex));
24+
private static readonly Lazy<Base32> zBase32 = new (() => new Base32(Base32Alphabet.ZBase32));
25+
private static readonly Lazy<Base32> geohash = new (() => new Base32(Base32Alphabet.Geohash));
26+
private static readonly Lazy<Base32> bech32 = new (() => new Base32(Base32Alphabet.Bech32));
27+
private static readonly Lazy<Base32> filecoin = new (() => new Base32(Base32Alphabet.FileCoin));
2728

2829
/// <summary>
2930
/// Initializes a new instance of the <see cref="Base32"/> class with a
@@ -81,19 +82,15 @@ private enum DecodeResult
8182
/// </summary>
8283
public static Base32 Bech32 => bech32.Value;
8384

85+
/// <summary>
86+
/// Gets FileCoin variant of Base32 coder.
87+
/// </summary>
88+
public static Base32 FileCoin => filecoin.Value;
89+
8490
/// <summary>
8591
/// Gets the encoding alphabet.
8692
/// </summary>
8793
public Base32Alphabet Alphabet { get; }
88-
/// <summary>
89-
/// Gets FileCoin variant of Base32 coder.
90-
/// </summary>
91-
public static Base32 FileCoin => filecoin.Value;
92-
93-
/// <summary>
94-
/// Gets the encoding alphabet.
95-
/// </summary>
96-
public Base32Alphabet Alphabet { get; }
9794

9895
/// <inheritdoc/>
9996
public int GetSafeByteCountForDecoding(ReadOnlySpan<char> text)
@@ -445,7 +442,7 @@ private DecodeResult internalDecode(
445442

446443
numBytesWritten = 0;
447444
int o = 0;
448-
for (int i = 0; i < input.Length; i++)
445+
for (int i = 0; i < input.Length; i++)
449446
{
450447
char c = input[i];
451448
int b = table[c] - 1;

src/Base32Alphabet.cs

+27-28
Original file line numberDiff line numberDiff line change
@@ -12,42 +12,45 @@ namespace SimpleBase;
1212
/// </summary>
1313
public class Base32Alphabet : CodingAlphabet
1414
{
15-
private static readonly Lazy<Base32Alphabet> rfc4648Alphabet = new(
16-
() => new Base32Alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"));
15+
private static readonly Lazy<Base32Alphabet> rfc4648Alphabet = new
16+
(() => new Base32Alphabet("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"));
1717

18-
private static readonly Lazy<Base32Alphabet> extendedHexAlphabet = new(
19-
() => new Base32Alphabet("0123456789ABCDEFGHIJKLMNOPQRSTUV"));
18+
private static readonly Lazy<Base32Alphabet> extendedHexAlphabet = new
19+
(() => new Base32Alphabet("0123456789ABCDEFGHIJKLMNOPQRSTUV"));
2020

21-
private static readonly Lazy<Base32Alphabet> zBase32Alphabet = new(
22-
() => new Base32Alphabet("ybndrfg8ejkmcpqxot1uwisza345h769"));
21+
private static readonly Lazy<Base32Alphabet> zBase32Alphabet = new
22+
(() => new Base32Alphabet("ybndrfg8ejkmcpqxot1uwisza345h769"));
2323

24-
private static readonly Lazy<Base32Alphabet> geohashAlphabet = new(
25-
() => new Base32Alphabet("0123456789bcdefghjkmnpqrstuvwxyz"));
24+
private static readonly Lazy<Base32Alphabet> geohashAlphabet = new
25+
(() => new Base32Alphabet("0123456789bcdefghjkmnpqrstuvwxyz"));
2626

27-
private static readonly Lazy<Base32Alphabet> bech32Alphabet = new(
28-
() => new Base32Alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"));
27+
private static readonly Lazy<Base32Alphabet> bech32Alphabet = new
28+
(() => new Base32Alphabet("qpzry9x8gf2tvdw0s3jn54khce6mua7l"));
2929

30-
private static readonly Lazy<AliasedBase32Alphabet> crockfordAlphabet = new(
31-
() => new AliasedBase32Alphabet(
30+
private static readonly Lazy<Base32Alphabet> fileCoinAlphabet = new
31+
(() => new Base32Alphabet("abcdefghijklmnopqrstuvwxyz234567"));
32+
33+
private static readonly Lazy<AliasedBase32Alphabet> crockfordAlphabet = new
34+
(() => new AliasedBase32Alphabet(
3235
"0123456789ABCDEFGHJKMNPQRSTVWXYZ",
3336
new CharMap[]
3437
{
35-
new('O', '0'),
36-
new('I', '1'),
37-
new('L', '1'),
38+
new ('O', '0'),
39+
new ('I', '1'),
40+
new ('L', '1'),
3841
}));
3942

40-
private static readonly Lazy<AliasedBase32Alphabet> base32HAlphabet = new(
43+
private static readonly Lazy<AliasedBase32Alphabet> base32HAlphabet = new (
4144
() => new AliasedBase32Alphabet(
4245
"0123456789ABCDEFGHJKLMNPQRTVWXYZ",
4346
paddingChar: '0',
4447
PaddingPosition.Start,
4548
new CharMap[]
4649
{
47-
new('O', '0'),
48-
new('I', '1'),
49-
new('S', '5'),
50-
new('U', 'V'),
50+
new ('O', '0'),
51+
new ('I', '1'),
52+
new ('S', '5'),
53+
new ('U', 'V'),
5154
}));
5255

5356
/// <summary>
@@ -98,15 +101,11 @@ public Base32Alphabet(string alphabet, char paddingChar, PaddingPosition padding
98101
/// </summary>
99102
public static Base32Alphabet Geohash => geohashAlphabet.Value;
100103

101-
/// <summary>
102-
/// Gets FileCoin alphabet.
103-
/// </summary>
104-
public static Base32Alphabet FileCoin => fileCoinAlphabet.Value;
104+
/// <summary>
105+
/// Gets FileCoin alphabet.
106+
/// </summary>
107+
public static Base32Alphabet FileCoin => fileCoinAlphabet.Value;
105108

106-
/// <summary>
107-
/// Gets the padding character used in encoding.
108-
/// </summary>
109-
public char PaddingChar { get; } = '=';
110109
/// <summary>
111110
/// Gets Base32H alphabet.
112111
/// </summary>

src/Base58.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ public sealed class Base58 : IBaseCoder, INonAllocatingBaseCoder
2323
private const int maxCheckPayloadLength = 256;
2424
private const int sha256Bytes = 32;
2525
private const int sha256DigestBytes = 4;
26-
private static readonly Lazy<Base58> bitcoin = new(() => new Base58(Base58Alphabet.Bitcoin));
27-
private static readonly Lazy<Base58> ripple = new(() => new Base58(Base58Alphabet.Ripple));
28-
private static readonly Lazy<Base58> flickr = new(() => new Base58(Base58Alphabet.Flickr));
26+
private static readonly Lazy<Base58> bitcoin = new (() => new Base58(Base58Alphabet.Bitcoin));
27+
private static readonly Lazy<Base58> ripple = new (() => new Base58(Base58Alphabet.Ripple));
28+
private static readonly Lazy<Base58> flickr = new (() => new Base58(Base58Alphabet.Flickr));
2929

3030
/// <summary>
3131
/// Initializes a new instance of the <see cref="Base58"/> class

src/Base58Alphabet.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ namespace SimpleBase;
1212
/// </summary>
1313
public sealed class Base58Alphabet : CodingAlphabet
1414
{
15-
private static readonly Lazy<Base58Alphabet> bitcoinAlphabet = new(()
15+
private static readonly Lazy<Base58Alphabet> bitcoinAlphabet = new (()
1616
=> new Base58Alphabet("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"));
1717

18-
private static readonly Lazy<Base58Alphabet> rippleAlphabet = new (()
19-
=> new Base58Alphabet("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"));
18+
private static readonly Lazy<Base58Alphabet> rippleAlphabet = new (()
19+
=> new Base58Alphabet("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz"));
2020

21-
private static readonly Lazy<Base58Alphabet> flickrAlphabet = new (()
22-
=> new Base58Alphabet("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"));
21+
private static readonly Lazy<Base58Alphabet> flickrAlphabet = new (()
22+
=> new Base58Alphabet("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"));
2323

2424
/// <summary>
2525
/// Initializes a new instance of the <see cref="Base58Alphabet"/> class

src/Base85.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public class Base85 : IBaseCoder, IBaseStreamCoder, INonAllocatingBaseCoder
2121
private const int stringBlockSize = 5;
2222
private const long fourSpaceChars = 0x20202020;
2323
private const int decodeBufferSize = 5120; // don't remember what was special with this number
24-
private static readonly Lazy<Base85> z85 = new(() => new Base85(Base85Alphabet.Z85));
25-
private static readonly Lazy<Base85> ascii85 = new(() => new Base85(Base85Alphabet.Ascii85));
26-
private static readonly Lazy<Base85Ipv6> rfc1924 = new(() => new Base85Ipv6(Base85Alphabet.Rfc1924));
24+
private static readonly Lazy<Base85> z85 = new (() => new Base85(Base85Alphabet.Z85));
25+
private static readonly Lazy<Base85> ascii85 = new (() => new Base85(Base85Alphabet.Ascii85));
26+
private static readonly Lazy<Base85Ipv6> rfc1924 = new (() => new Base85Ipv6(Base85Alphabet.Rfc1924));
2727

2828
/// <summary>
2929
/// Initializes a new instance of the <see cref="Base85"/> class

src/Base85Alphabet.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ namespace SimpleBase;
1212
/// </summary>
1313
public sealed class Base85Alphabet : CodingAlphabet
1414
{
15-
private static readonly Lazy<Base85Alphabet> z85 = new(() => new Base85Alphabet(
15+
private static readonly Lazy<Base85Alphabet> z85 = new (() => new Base85Alphabet(
1616
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#"));
1717

18-
private static readonly Lazy<Base85Alphabet> ascii85 = new (() => new Base85Alphabet(
19-
"!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstu",
20-
allZeroShortcut: 'z',
21-
allSpaceShortcut: 'y'));
18+
private static readonly Lazy<Base85Alphabet> ascii85 = new (() => new Base85Alphabet(
19+
"!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstu",
20+
allZeroShortcut: 'z',
21+
allSpaceShortcut: 'y'));
2222

23-
private static readonly Lazy<Base85Alphabet> rfc1924 = new(() => new Base85Alphabet(
23+
private static readonly Lazy<Base85Alphabet> rfc1924 = new (() => new Base85Alphabet(
2424
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!#$%&()*+-;<=>?@^_`{|}~"));
2525

2626
/// <summary>

src/Base85Ipv6.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class Base85Ipv6 : Base85
2626
{
2727
private const int ipv6bytes = 16;
2828
private const int ipv6chars = 20;
29-
private static readonly BigInteger divisor = new(85);
29+
private static readonly BigInteger divisor = new (85);
3030

3131
/// <summary>
3232
/// Initializes a new instance of the <see cref="Base85Ipv6"/> class.

0 commit comments

Comments
 (0)