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
4343using SmartHealthCard .QRCode ;
4444using SmartHealthCard .Token ;
4545using SmartHealthCard .Token .Certificates ;
46+ using SmartHealthCard .Token .Exceptions ;
4647using SmartHealthCard .Token .Model .Shc ;
4748using System ;
4849using 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#
127142using SmartHealthCard .Token ;
128143using SmartHealthCard .Token .Certificates ;
144+ using SmartHealthCard .Token .Exceptions ;
129145using SmartHealthCard .Token .Model .Jwks ;
130146using SmartHealthCard .Token .Model .Shc ;
147+ using SmartHealthCard .Token .Providers ;
148+ using SmartHealthCard .Token .Support ;
131149using System ;
132150using System .Collections .Generic ;
133151using System .Security .Cryptography .X509Certificates ;
152+ using System .Threading ;
134153using System .Threading .Tasks ;
135154
136155namespace 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```
0 commit comments