From 8802cb794be1cfb2e5b74005e917910a1171b725 Mon Sep 17 00:00:00 2001 From: Klaus Fischer <klaus.fischer@eloware.com> Date: Thu, 7 Jul 2022 22:05:18 +0200 Subject: [PATCH] Added error message for macOS not supported. Resolved compiler warnings --- E2ETests/SenderTest.cs | 2 +- Encryption/JoseEncryptor.cs | 38 ++++++++++++++----- FitConnect/FluentSender.cs | 4 +- FitConnect/Models/Destination.cs | 4 +- FitConnect/Models/Submission.cs | 4 +- Services/Models/CallbackDto.cs | 2 +- Services/Models/OAuthAccessToken.cs | 6 +-- Services/Models/v1/Case/EventLogDto.cs | 8 ++-- .../v1/Destination/ContactInformationDto.cs | 10 ++--- .../v1/Destination/CreateDestinationDto.cs | 16 ++++---- .../v1/Destination/DestinationListDto.cs | 8 ++-- .../v1/Destination/DestinationServiceDto.cs | 6 +-- .../v1/Destination/PatchDestinationDto.cs | 14 +++---- .../v1/Destination/PrivateDestinationDto.cs | 16 ++++---- .../v1/Destination/SubmissionSchemaDto.cs | 2 +- .../v1/Destination/UpdateDestinationDto.cs | 14 +++---- .../v1/Submission/SubmissionCreatedDto.cs | 6 +-- .../Models/v1/Submission/SubmissionDto.cs | 16 ++++---- .../v1/Submission/SubmissionForPickupDto.cs | 6 +-- .../v1/Submission/SubmissionReducedDto.cs | 12 +++--- .../v1/Submission/SubmissionsForPickupDto.cs | 8 ++-- .../v1/Submission/SubmitSubmissionDto.cs | 4 +- 22 files changed, 112 insertions(+), 94 deletions(-) diff --git a/E2ETests/SenderTest.cs b/E2ETests/SenderTest.cs index 2f6be876..89e24617 100644 --- a/E2ETests/SenderTest.cs +++ b/E2ETests/SenderTest.cs @@ -85,7 +85,7 @@ public class SenderTest { // Arrange var dut = _fluentSender .WithDestination(desitnationId) - .WithServiceType("ServcieName", "urn:de:fim:leika:leistung:99400048079000"); + .WithServiceType("ServiceName", "urn:de:fim:leika:leistung:99400048079000"); var attachments = new List<Attachment>(); for (var i = 0; i < 10; i++) { diff --git a/Encryption/JoseEncryptor.cs b/Encryption/JoseEncryptor.cs index 8d4d7adc..c930cd2c 100644 --- a/Encryption/JoseEncryptor.cs +++ b/Encryption/JoseEncryptor.cs @@ -7,6 +7,9 @@ public class JoseEncryptor : IEncryptor { private const JweCompression Compression = JweCompression.DEF; private const JweAlgorithm Algorithm = JweAlgorithm.RSA_OAEP; + private const string ErrorMessage = + "On macOS add DYLD_LIBRARY_PATH to your environment variables. Look at the README for more information."; + private (string plainText, byte[] plainBytes, byte[] tag) Decrypt(Jwk key, string payload) { var result = JWE.Decrypt(payload, key); @@ -15,21 +18,36 @@ public class JoseEncryptor : IEncryptor { public (string plainText, byte[] plainBytes, byte[] tag) Decrypt(string key, string cipher) { - var jwk = Jwk.FromJson(key, new Jose.JsonMapper()); - return Decrypt(jwk, cipher); + try { + var jwk = Jwk.FromJson(key, new Jose.JsonMapper()); + return Decrypt(jwk, cipher); + } + catch (PlatformNotSupportedException e) { + throw new PlatformNotSupportedException(ErrorMessage, e); + } } public string Encrypt(string key, string plain) { - var jwk = Jwk.FromJson(key, new Jose.JsonMapper()); - return JWE.Encrypt(plain, - new JweRecipient[] { new JweRecipient(Algorithm, jwk) }, - Encryption, compression: Compression); + try { + var jwk = Jwk.FromJson(key, new Jose.JsonMapper()); + return JWE.Encrypt(plain, + new JweRecipient[] { new JweRecipient(Algorithm, jwk) }, + Encryption, compression: Compression); + } + catch (PlatformNotSupportedException e) { + throw new PlatformNotSupportedException(ErrorMessage, e); + } } public string Encrypt(string key, byte[] plain) { - var jwk = Jwk.FromJson(key, new Jose.JsonMapper()); - return JWE.EncryptBytes(plain, - new JweRecipient[] { new JweRecipient(Algorithm, jwk) }, - Encryption, compression: Compression); + try { + var jwk = Jwk.FromJson(key, new Jose.JsonMapper()); + return JWE.EncryptBytes(plain, + new JweRecipient[] { new JweRecipient(Algorithm, jwk) }, + Encryption, compression: Compression); + } + catch (PlatformNotSupportedException e) { + throw new PlatformNotSupportedException(ErrorMessage, e); + } } } diff --git a/FitConnect/FluentSender.cs b/FitConnect/FluentSender.cs index 5f312867..7b0eeaaf 100644 --- a/FitConnect/FluentSender.cs +++ b/FitConnect/FluentSender.cs @@ -38,9 +38,9 @@ public class FluentSender : Sender, IFluentSender, IFluentSenderWithDestination, routeService, destinationService, logger) { } - public string PublicKey { get; set; } + public string? PublicKey { get; set; } public CreateSubmissionDto? NewSubmission { get; set; } - public Submission Submission { get; set; } + public Submission? Submission { get; set; } public IFluentSenderWithDestination FindDestinationId(string leiaKey, string? ags, string? ars, diff --git a/FitConnect/Models/Destination.cs b/FitConnect/Models/Destination.cs index fe73e08a..7230666d 100644 --- a/FitConnect/Models/Destination.cs +++ b/FitConnect/Models/Destination.cs @@ -1,11 +1,11 @@ namespace FitConnect.Models; public class Destination { - public string LeikaKey { get; set; } + public string? LeikaKey { get; set; } public string? Ags { get; set; } public string? Ars { get; set; } public string? AreaId { get; set; } - public string DestinationId { get; set; } + public string? DestinationId { get; set; } public bool Valid => !((string.IsNullOrWhiteSpace(Ags) && string.IsNullOrWhiteSpace(Ars) diff --git a/FitConnect/Models/Submission.cs b/FitConnect/Models/Submission.cs index 6917a36f..638397fe 100644 --- a/FitConnect/Models/Submission.cs +++ b/FitConnect/Models/Submission.cs @@ -4,9 +4,9 @@ using FitConnect.Services.Models.v1; namespace FitConnect.Models; public class Submission { - public string Id { get; set; } + public string? Id { get; set; } public string? CaseId { get; set; } - public Destination Destination { get; set; } = new(); + public Destination? Destination { get; set; } = new(); public string DestinationId { get => Destination.DestinationId; diff --git a/Services/Models/CallbackDto.cs b/Services/Models/CallbackDto.cs index 2a2e45ad..0228e1f8 100644 --- a/Services/Models/CallbackDto.cs +++ b/Services/Models/CallbackDto.cs @@ -4,7 +4,7 @@ namespace FitConnect.Services.Models; public class CallbackDto { [JsonPropertyName("url")] - public string Url { get; set; } + public string? Url { get; set; } [JsonPropertyName("secret")] public string? Secret { get; set; } diff --git a/Services/Models/OAuthAccessToken.cs b/Services/Models/OAuthAccessToken.cs index 3fc70d9b..57b9ac9e 100644 --- a/Services/Models/OAuthAccessToken.cs +++ b/Services/Models/OAuthAccessToken.cs @@ -4,13 +4,13 @@ namespace FitConnect.Services.Models; public class OAuthAccessToken { [JsonPropertyName("access_token")] - public string AccessToken { get; set; } + public string? AccessToken { get; set; } [JsonPropertyName("scope")] - public string Scope { get; set; } + public string? Scope { get; set; } [JsonPropertyName("token_type")] - public string TokenType { get; set; } + public string? TokenType { get; set; } [JsonPropertyName("expires_in")] public int ExpiresIn { get; set; } diff --git a/Services/Models/v1/Case/EventLogDto.cs b/Services/Models/v1/Case/EventLogDto.cs index 54598c77..6e40e32a 100644 --- a/Services/Models/v1/Case/EventLogDto.cs +++ b/Services/Models/v1/Case/EventLogDto.cs @@ -4,14 +4,14 @@ namespace FitConnect.Services.Models.v1; public class EventLogDto { [JsonPropertyName("count")] - public int Count; + public int Count{ get; set; } [JsonPropertyName("eventLog")] - public List<string> EventLog; + public List<string>? EventLog{ get; set; } [JsonPropertyName("offset")] - public int Offset; + public int Offset{ get; set; } [JsonPropertyName("totalCount")] - public long TotalCount; + public long TotalCount{ get; set; } } diff --git a/Services/Models/v1/Destination/ContactInformationDto.cs b/Services/Models/v1/Destination/ContactInformationDto.cs index cb65d109..c715f6ad 100644 --- a/Services/Models/v1/Destination/ContactInformationDto.cs +++ b/Services/Models/v1/Destination/ContactInformationDto.cs @@ -4,17 +4,17 @@ namespace FitConnect.Services.Models.v1; public class ContactInformationDto { [JsonPropertyName("address")] - public string Address; + public string? Address{ get; set; } [JsonPropertyName("email")] - public string Email; + public string? Email{ get; set; } [JsonPropertyName("legalName")] - public string LegalName; + public string? LegalName{ get; set; } [JsonPropertyName("phone")] - public string Phone; + public string? Phone{ get; set; } [JsonPropertyName("unit")] - public string Unit; + public string? Unit{ get; set; } } diff --git a/Services/Models/v1/Destination/CreateDestinationDto.cs b/Services/Models/v1/Destination/CreateDestinationDto.cs index 984fb40e..8f731baf 100644 --- a/Services/Models/v1/Destination/CreateDestinationDto.cs +++ b/Services/Models/v1/Destination/CreateDestinationDto.cs @@ -4,32 +4,32 @@ namespace FitConnect.Services.Models.v1; public class CreateDestinationDto { [JsonPropertyName("callback")] - public CallbackDto Callback; + public CallbackDto? Callback { get; set; } [JsonPropertyName("contactInformation")] - public ContactInformationDto ContactInformation; + public ContactInformationDto? ContactInformation { get; set; } [JsonPropertyName("encryptionKid")] - public string EncryptionKid; + public string? EncryptionKid { get; set; } [JsonPropertyName("encryptionPublicKey")] - public string EncryptionPublicKey; + public string? EncryptionPublicKey { get; set; } [JsonPropertyName("metadataVersions")] - public List<string> metadataVersions; + public List<string>? MetadataVersions { get; set; } [JsonPropertyName("replyChannels")] - public DestinationReplyChannelsDto ReplyChannels; + public DestinationReplyChannelsDto? ReplyChannels { get; set; } [JsonPropertyName("services")] - public List<DestinationServiceDto> Services; + public List<DestinationServiceDto>? Services { get; set; } [JsonPropertyName("signingPublicKey")] - public string SigningPublicKey; + public string? SigningPublicKey { get; set; } } diff --git a/Services/Models/v1/Destination/DestinationListDto.cs b/Services/Models/v1/Destination/DestinationListDto.cs index e90eeca4..ce9324b8 100644 --- a/Services/Models/v1/Destination/DestinationListDto.cs +++ b/Services/Models/v1/Destination/DestinationListDto.cs @@ -4,17 +4,17 @@ namespace FitConnect.Services.Models.v1; public class DestinationListDto { [JsonPropertyName("count")] - public int Count; + public int Count{ get; set; } [JsonPropertyName("destinations")] - public List<PrivateDestinationDto> Destinations; + public List<PrivateDestinationDto>? Destinations{ get; set; } [JsonPropertyName("offset")] - public int Offset; + public int Offset{ get; set; } [JsonPropertyName("totalCount")] - public long TotalCount; + public long TotalCount{ get; set; } } diff --git a/Services/Models/v1/Destination/DestinationServiceDto.cs b/Services/Models/v1/Destination/DestinationServiceDto.cs index 9bb36958..bb79fda5 100644 --- a/Services/Models/v1/Destination/DestinationServiceDto.cs +++ b/Services/Models/v1/Destination/DestinationServiceDto.cs @@ -4,12 +4,12 @@ namespace FitConnect.Services.Models.v1; public class DestinationServiceDto { [JsonPropertyName("identifier")] - public string Identifier; + public string? Identifier{ get; set; } [JsonPropertyName("regions")] - public List<string> Regions; + public List<string>? Regions{ get; set; } [JsonPropertyName("submissionSchemas")] - public List<SubmissionSchemaDto> SubmissionSchemas; + public List<SubmissionSchemaDto>? SubmissionSchemas{ get; set; } } diff --git a/Services/Models/v1/Destination/PatchDestinationDto.cs b/Services/Models/v1/Destination/PatchDestinationDto.cs index 16986f77..844682f2 100644 --- a/Services/Models/v1/Destination/PatchDestinationDto.cs +++ b/Services/Models/v1/Destination/PatchDestinationDto.cs @@ -4,28 +4,28 @@ namespace FitConnect.Services.Models.v1; public class PatchDestinationDto { [JsonPropertyName("callback")] - public CallbackDto Callback; + public CallbackDto? Callback{ get; set; } [JsonPropertyName("contactInformation")] - public ContactInformationDto ContactInformation; + public ContactInformationDto? ContactInformation{ get; set; } [JsonPropertyName("encryptionKid")] - public string EncryptionKid; + public string? EncryptionKid{ get; set; } [JsonPropertyName("metadataVersions")] - public List<string> metadataVersions; + public List<string>? metadataVersions{ get; set; } [JsonPropertyName("replyChannels")] - public DestinationReplyChannelsDto ReplyChannels; + public DestinationReplyChannelsDto? ReplyChannels{ get; set; } [JsonPropertyName("services")] - public List<DestinationServiceDto> Services; + public List<DestinationServiceDto>? Services{ get; set; } [JsonPropertyName("status")] - public string Status; + public string? Status{ get; set; } } diff --git a/Services/Models/v1/Destination/PrivateDestinationDto.cs b/Services/Models/v1/Destination/PrivateDestinationDto.cs index 28f51708..e2dcc4e4 100644 --- a/Services/Models/v1/Destination/PrivateDestinationDto.cs +++ b/Services/Models/v1/Destination/PrivateDestinationDto.cs @@ -4,32 +4,32 @@ namespace FitConnect.Services.Models.v1; public class PrivateDestinationDto { [JsonPropertyName("callback")] - public CallbackDto Callback; + public CallbackDto? Callback{ get; set; } [JsonPropertyName("contactInformation")] - public ContactInformationDto ContactInformation; + public ContactInformationDto? ContactInformation{ get; set; } [JsonPropertyName("destinationId")] - public string DestinationId; + public string? DestinationId{ get; set; } [JsonPropertyName("encryptionKid")] - public string EncryptionKid; + public string? EncryptionKid{ get; set; } [JsonPropertyName("metadataVersions")] - public List<string> MetadataVersions; + public List<string>? MetadataVersions{ get; set; } [JsonPropertyName("replyChannels")] - public DestinationReplyChannelsDto ReplyChannels; + public DestinationReplyChannelsDto? ReplyChannels{ get; set; } [JsonPropertyName("services")] - public List<DestinationServiceDto> Services; + public List<DestinationServiceDto>? Services{ get; set; } [JsonPropertyName("status")] - public string Status; + public string? Status{ get; set; } } diff --git a/Services/Models/v1/Destination/SubmissionSchemaDto.cs b/Services/Models/v1/Destination/SubmissionSchemaDto.cs index 39a509d7..e44d9029 100644 --- a/Services/Models/v1/Destination/SubmissionSchemaDto.cs +++ b/Services/Models/v1/Destination/SubmissionSchemaDto.cs @@ -8,5 +8,5 @@ public class SubmissionSchemaDto { public int mimeType; [JsonPropertyName("schemaUri")] - public string schemaUri; + public string? SchemaUri{ get; set; } } diff --git a/Services/Models/v1/Destination/UpdateDestinationDto.cs b/Services/Models/v1/Destination/UpdateDestinationDto.cs index ab9c5677..8a9d8493 100644 --- a/Services/Models/v1/Destination/UpdateDestinationDto.cs +++ b/Services/Models/v1/Destination/UpdateDestinationDto.cs @@ -4,28 +4,28 @@ namespace FitConnect.Services.Models.v1; public class UpdateDestinationDto { [JsonPropertyName("callback")] - public CallbackDto Callback; + public CallbackDto? Callback{ get; set; } [JsonPropertyName("contactInformation")] - public ContactInformationDto ContactInformation; + public ContactInformationDto? ContactInformation{ get; set; } [JsonPropertyName("encryptionKid")] - public string EncryptionKid; + public string? EncryptionKid{ get; set; } [JsonPropertyName("metadataVersions")] - public List<string> metadataVersions; + public List<string>? metadataVersions{ get; set; } [JsonPropertyName("replyChannels")] - public DestinationReplyChannelsDto ReplyChannels; + public DestinationReplyChannelsDto? ReplyChannels{ get; set; } [JsonPropertyName("services")] - public List<DestinationServiceDto> Services; + public List<DestinationServiceDto>? Services{ get; set; } [JsonPropertyName("status")] - public string Status; + public string? Status{ get; set; } } diff --git a/Services/Models/v1/Submission/SubmissionCreatedDto.cs b/Services/Models/v1/Submission/SubmissionCreatedDto.cs index 4b4ac183..91da9d86 100644 --- a/Services/Models/v1/Submission/SubmissionCreatedDto.cs +++ b/Services/Models/v1/Submission/SubmissionCreatedDto.cs @@ -4,11 +4,11 @@ namespace FitConnect.Services.Models.v1; public class SubmissionCreatedDto { [JsonPropertyName("destinationId")] - public string DestinationId { get; set; } + public string? DestinationId { get; set; } [JsonPropertyName("submissionId")] - public string SubmissionId { get; set; } + public string? SubmissionId { get; set; } [JsonPropertyName("caseId")] - public string CaseId { get; set; } + public string? CaseId { get; set; } } diff --git a/Services/Models/v1/Submission/SubmissionDto.cs b/Services/Models/v1/Submission/SubmissionDto.cs index 9430bbc5..05a07992 100644 --- a/Services/Models/v1/Submission/SubmissionDto.cs +++ b/Services/Models/v1/Submission/SubmissionDto.cs @@ -4,32 +4,32 @@ namespace FitConnect.Services.Models.v1; public class SubmissionDto { [JsonPropertyName("attachments")] - public List<string> Attachments; + public List<string>? Attachments{ get; set; } [JsonPropertyName("callback")] - public CallbackDto Callback; + public CallbackDto? Callback{ get; set; } [JsonPropertyName("caseId")] - public string CaseId; + public string? CaseId{ get; set; } [JsonPropertyName("destinationId")] - public string DestinationId; + public string? DestinationId{ get; set; } [JsonPropertyName("encryptedData")] - public string EncryptedData; + public string? EncryptedData{ get; set; } [JsonPropertyName("encryptedMetadata")] - public string EncryptedMetadata; + public string? EncryptedMetadata{ get; set; } [JsonPropertyName("serviceType")] - public ServiceTypeDto ServiceType; + public ServiceTypeDto? ServiceType{ get; set; } [JsonPropertyName("submissionId")] - public string SubmissionId; + public string? SubmissionId{ get; set; } } diff --git a/Services/Models/v1/Submission/SubmissionForPickupDto.cs b/Services/Models/v1/Submission/SubmissionForPickupDto.cs index 433b8983..d4fdfba3 100644 --- a/Services/Models/v1/Submission/SubmissionForPickupDto.cs +++ b/Services/Models/v1/Submission/SubmissionForPickupDto.cs @@ -4,11 +4,11 @@ namespace FitConnect.Services.Models.v1; public class SubmissionForPickupDto { [JsonPropertyName("caseId")] - public string CaseId; + public string? CaseId{ get; set; } [JsonPropertyName("destinationId")] - public string DestinationId; + public string? DestinationId{ get; set; } [JsonPropertyName("submissionId")] - public string SubmissionId; + public string? SubmissionId{ get; set; } } diff --git a/Services/Models/v1/Submission/SubmissionReducedDto.cs b/Services/Models/v1/Submission/SubmissionReducedDto.cs index 768d3632..e01f28a8 100644 --- a/Services/Models/v1/Submission/SubmissionReducedDto.cs +++ b/Services/Models/v1/Submission/SubmissionReducedDto.cs @@ -4,24 +4,24 @@ namespace FitConnect.Services.Models.v1; public class SubmissionReducedDto { [JsonPropertyName("serviceType")] - private ServiceTypeDto _serviceTypeDto; + private ServiceTypeDto? ServiceTypeDto { get; set; } [JsonPropertyName("attachments")] - private List<string> Attachments; + private List<string>? Attachments { get; set; } [JsonPropertyName("callback")] - private CallbackDto Callback; + private CallbackDto? Callback { get; set; } [JsonPropertyName("caseId")] - private string CaseId; + private string? CaseId { get; set; } [JsonPropertyName("destinationId")] - private string DestinationId; + private string? DestinationId { get; set; } [JsonPropertyName("submissionId")] - private string SubmissionId; + private string? SubmissionId { get; set; } } diff --git a/Services/Models/v1/Submission/SubmissionsForPickupDto.cs b/Services/Models/v1/Submission/SubmissionsForPickupDto.cs index 564c2d8a..cd785044 100644 --- a/Services/Models/v1/Submission/SubmissionsForPickupDto.cs +++ b/Services/Models/v1/Submission/SubmissionsForPickupDto.cs @@ -4,14 +4,14 @@ namespace FitConnect.Services.Models.v1; public class SubmissionsForPickupDto { [JsonPropertyName("count")] - public int Count; + public int Count { get; set; } [JsonPropertyName("offset")] - public int Offset; + public int Offset { get; set; } [JsonPropertyName("submissions")] - public List<SubmissionForPickupDto> Submissions; + public List<SubmissionForPickupDto>? Submissions { get; set; } [JsonPropertyName("totalCount")] - public long TotalCount; + public long TotalCount { get; set; } } diff --git a/Services/Models/v1/Submission/SubmitSubmissionDto.cs b/Services/Models/v1/Submission/SubmitSubmissionDto.cs index 14271f2e..061aa637 100644 --- a/Services/Models/v1/Submission/SubmitSubmissionDto.cs +++ b/Services/Models/v1/Submission/SubmitSubmissionDto.cs @@ -4,8 +4,8 @@ namespace FitConnect.Services.Models.v1; public class SubmitSubmissionDto { [JsonPropertyName("encryptedData")] - public string? EncryptedData; + public string? EncryptedData{ get; set; } [JsonPropertyName("encryptedMetadata")] - public string EncryptedMetadata; + public string? EncryptedMetadata{ get; set; } } -- GitLab