Skip to content
Snippets Groups Projects
Commit d70ff16e authored by Klaus Fischer's avatar Klaus Fischer
Browse files

feature: throwing exception on missing content type

parent cec7e836
No related branches found
No related tags found
1 merge request!108Bug/1244 cty
using System.Net.Mime;
using FitConnect.Exceptions;
using Jose;
using Microsoft.IdentityModel.Tokens;
// ReSharper disable RedundantExplicitArrayCreation
......@@ -30,6 +32,8 @@ public class JoseEncryptor : IEncryptor {
}
public string Encrypt(string key, string plain, string contentType) {
if (contentType.IsNullOrEmpty())
throw new FitConnectSenderException("Content Type is not set");
try {
var jwk = Jwk.FromJson(key, new JsonMapper());
if (!jwk.KeyOps.Contains(EncryptionSettings.KeyOpsWrapKey))
......@@ -51,6 +55,9 @@ public class JoseEncryptor : IEncryptor {
}
public string Encrypt(string key, byte[] plain, string contentType) {
if (contentType.IsNullOrEmpty())
throw new FitConnectSenderException("Content Type is not set");
try {
var jwk = Jwk.FromJson(key, new JsonMapper());
return JWE.EncryptBytes(plain,
......
......@@ -242,7 +242,7 @@ public abstract class FitConnectClient: IFitConnectClient {
/// <param name="attachment"></param>
/// <returns></returns>
public KeyValuePair<Guid, string> Encrypt(string publicKey, Attachment attachment) {
var content = Encryption.Encrypt(attachment.GetBytes(), publicKey);
var content = Encryption.Encrypt(attachment.GetBytes(), publicKey, attachment.MimeType);
return new KeyValuePair<Guid, string>(attachment.Id, content);
}
......
......@@ -31,11 +31,11 @@ public class StraightForwardTest : EndToEndTestBase {
.SetServiceType(Settings.ServiceIdentifier, "Straight forward test")
.SetJsonData(JSON_DATA, new Uri(JSON_SCHEMA_URI))
.AddAttachments(
Attachment.FromPath("Test.pdf", "application/pdf", description: "Attachment #1",
Attachment.FromPath("Test.pdf", MediaTypeNames.Application.Pdf, description: "Attachment #1",
fileName: "Test.pdf"),
Attachment.FromPath("Test.pdf", "application/pdf", description: "Attachment #2",
Attachment.FromPath("Test.pdf", MediaTypeNames.Application.Pdf, description: "Attachment #2",
fileName: "Test.pdf"))
.AddAttachment(Attachment.FromPath("Test.pdf", "application/pdf",
.AddAttachment(Attachment.FromPath("Test.pdf", MediaTypeNames.Application.Pdf,
description: "Attachment #3", fileName: "Test.pdf"))
.AddAttachment(Attachment.FromByteArray(
Encoding.UTF8.GetBytes("{\"message\":\"Hello World\"}"),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment