Skip to content

Commit d6b2e22

Browse files
committed
Updated doco in readme file
1 parent f94e6a6 commit d6b2e22

3 files changed

Lines changed: 59 additions & 13 deletions

File tree

README.md

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
## [SmartHealthCard.Token](https://www.nuget.org/packages/SmartHealthCard.Token/0.1.0-alpha.1): Encode, Decode & Verifiy SMART Health Card JWS tokens
2626
```
27-
Install-Package SmartHealthCard.QRCode -Version 0.1.0-alpha.1
27+
Install-Package SmartHealthCard.QRCode -Version 0.1.0-alpha.3
2828
```
2929

3030

@@ -43,6 +43,7 @@ Install-Package SmartHealthCard.QRCode -Version 0.1.0-alpha.1
4343
using SmartHealthCard.QRCode;
4444
using SmartHealthCard.Token;
4545
using SmartHealthCard.Token.Certificates;
46+
using SmartHealthCard.Token.Exceptions;
4647
using SmartHealthCard.Token.Model.Shc;
4748
using System;
4849
using System.Collections.Generic;
@@ -100,8 +101,22 @@ namespace SHC.EncoderDemo
100101
//Instantiate the Smart Health Card Encoder
101102
SmartHealthCardEncoder SmartHealthCardEncoder = new SmartHealthCardEncoder();
102103

103-
//Get the Smart Health Card JWS Token
104-
string SmartHealthCardJwsToken = await SmartHealthCardEncoder.GetTokenAsync(Certificate, SmartHealthCard);
104+
string SmartHealthCardJwsToken = string.Empty;
105+
try
106+
{
107+
//Get the Smart Health Card JWS Token
108+
SmartHealthCardJwsToken = await SmartHealthCardEncoder.GetTokenAsync(Certificate, SmartHealthCard);
109+
}
110+
catch (SmartHealthCardEncoderException EncoderException)
111+
{
112+
Console.WriteLine("The SMART Health Card Encoder has found an error, please see message below:");
113+
Console.WriteLine(EncoderException.Message);
114+
}
115+
catch (Exception Exception)
116+
{
117+
Console.WriteLine("Oops, there is an unexpected development exception");
118+
Console.WriteLine(Exception.Message);
119+
}
105120

106121
//Instantiate the Smart Health Card QR Code Factory
107122
SmartHealthCardQRCodeEncoder SmartHealthCardQRCodeEncoder = new SmartHealthCardQRCodeEncoder();
@@ -126,11 +141,15 @@ namespace SHC.EncoderDemo
126141
```C#
127142
using SmartHealthCard.Token;
128143
using SmartHealthCard.Token.Certificates;
144+
using SmartHealthCard.Token.Exceptions;
129145
using SmartHealthCard.Token.Model.Jwks;
130146
using SmartHealthCard.Token.Model.Shc;
147+
using SmartHealthCard.Token.Providers;
148+
using SmartHealthCard.Token.Support;
131149
using System;
132150
using System.Collections.Generic;
133151
using System.Security.Cryptography.X509Certificates;
152+
using System.Threading;
134153
using System.Threading.Tasks;
135154

136155
namespace SHC.DecoderDemo
@@ -187,10 +206,15 @@ namespace SHC.DecoderDemo
187206
//Or decode and verify, returning the Smart Health Card as a JSON string, throws exceptions if not valid
188207
//string DecodedSmartHealthCardJson = await Decoder.DecodeToJsonAsync(SmartHealthCardJwsToken, Verify: true);
189208
}
190-
catch (Exception Exec)
209+
catch (SmartHealthCardDecoderException DecoderException)
191210
{
192211
Console.WriteLine("The SMART Health Card JWS token was invalid, please see message below:");
193-
Console.WriteLine(Exec.Message);
212+
Console.WriteLine(DecoderException.Message);
213+
}
214+
catch (Exception Exception)
215+
{
216+
Console.WriteLine("Oops, there is an unexpected development exception");
217+
Console.WriteLine(Exception.Message);
194218
}
195219
}
196220
}
@@ -204,7 +228,7 @@ namespace SHC.DecoderDemo
204228
this.Certificate = Certificate;
205229
}
206230

207-
public Task<JsonWebKeySet> GetJwksAsync(Uri WellKnownJwksUri)
231+
public Task<Result<JsonWebKeySet>> GetJwksAsync(Uri WellKnownJwksUri, CancellationToken? CancellationToken = null)
208232
{
209233
//In production the default implementation of this IJwksProvider interface would
210234
//retrieve the JWKS file from the provided 'WellKnownJwksUri' URL that is found in
@@ -213,9 +237,11 @@ namespace SHC.DecoderDemo
213237
//own JWKS which we have generated from our certificate as seen below.
214238
//This allows you to test before you have a publicly exposed endpoint for you JWKS.
215239
SmartHealthCardJwks SmartHealthCardJwks = new SmartHealthCardJwks();
216-
SmartHealthCard.Token.Model.Jwks.JsonWebKeySet Jwks = SmartHealthCardJwks.GetJsonWebKeySet(new List<X509Certificate2>() { Certificate });
217-
return Task.FromResult(Jwks);
240+
JsonWebKeySet Jwks = SmartHealthCardJwks.GetJsonWebKeySet(new List<X509Certificate2>() { Certificate });
241+
return Task.FromResult(Result<JsonWebKeySet>.Ok(Jwks));
218242
}
243+
244+
219245
}
220246
}
221247
```

SmartHealthCard.DecoderDemo/Program.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using SmartHealthCard.Token;
22
using SmartHealthCard.Token.Certificates;
3+
using SmartHealthCard.Token.Exceptions;
34
using SmartHealthCard.Token.Model.Jwks;
45
using SmartHealthCard.Token.Model.Shc;
56
using SmartHealthCard.Token.Providers;
@@ -64,10 +65,15 @@ static async Task DecoderDemoRunner()
6465
//Or decode and verify, returning the Smart Health Card as a JSON string, throws exceptions if not valid
6566
//string DecodedSmartHealthCardJson = await Decoder.DecodeToJsonAsync(SmartHealthCardJwsToken, Verify: true);
6667
}
67-
catch (Exception Exec)
68+
catch (SmartHealthCardDecoderException DecoderException)
6869
{
6970
Console.WriteLine("The SMART Health Card JWS token was invalid, please see message below:");
70-
Console.WriteLine(Exec.Message);
71+
Console.WriteLine(DecoderException.Message);
72+
}
73+
catch (Exception Exception)
74+
{
75+
Console.WriteLine("Oops, there is an unexpected development exception");
76+
Console.WriteLine(Exception.Message);
7177
}
7278
}
7379
}
@@ -91,7 +97,6 @@ public Task<Result<JsonWebKeySet>> GetJwksAsync(Uri WellKnownJwksUri, Cancellati
9197
//This allows you to test before you have a publicly exposed endpoint for you JWKS.
9298
SmartHealthCardJwks SmartHealthCardJwks = new SmartHealthCardJwks();
9399
JsonWebKeySet Jwks = SmartHealthCardJwks.GetJsonWebKeySet(new List<X509Certificate2>() { Certificate });
94-
95100
return Task.FromResult(Result<JsonWebKeySet>.Ok(Jwks));
96101
}
97102

SmartHealthCard.EncoderDemo/Program.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using SmartHealthCard.QRCode;
22
using SmartHealthCard.Token;
33
using SmartHealthCard.Token.Certificates;
4+
using SmartHealthCard.Token.Exceptions;
45
using SmartHealthCard.Token.Model.Shc;
56
using System;
67
using System.Collections.Generic;
@@ -58,8 +59,22 @@ static async Task EncoderDemoRunner()
5859
//Instantiate the Smart Health Card Encoder
5960
SmartHealthCardEncoder SmartHealthCardEncoder = new SmartHealthCardEncoder();
6061

61-
//Get the Smart Health Card JWS Token
62-
string SmartHealthCardJwsToken = await SmartHealthCardEncoder.GetTokenAsync(Certificate, SmartHealthCard);
62+
string SmartHealthCardJwsToken = string.Empty;
63+
try
64+
{
65+
//Get the Smart Health Card JWS Token
66+
SmartHealthCardJwsToken = await SmartHealthCardEncoder.GetTokenAsync(Certificate, SmartHealthCard);
67+
}
68+
catch (SmartHealthCardEncoderException EncoderException)
69+
{
70+
Console.WriteLine("The SMART Health Card Encoder has found an error, please see message below:");
71+
Console.WriteLine(EncoderException.Message);
72+
}
73+
catch (Exception Exception)
74+
{
75+
Console.WriteLine("Oops, there is an unexpected development exception");
76+
Console.WriteLine(Exception.Message);
77+
}
6378

6479
//Instantiate the Smart Health Card QR Code Factory
6580
SmartHealthCardQRCodeEncoder SmartHealthCardQRCodeEncoder = new SmartHealthCardQRCodeEncoder();

0 commit comments

Comments
 (0)