4using System.Threading.Tasks;
15 [CollectionName(
"QuickLoginAttachments")]
16 [Index(
"AttachmentId",
"Width",
"Height")]
50 public string ETag {
get;
set; }
65 public byte[]
Key {
get;
set; }
70 public byte[]
IV {
get;
set; }
76 internal async Task<byte[]> Load()
78 Aes Aes = Aes.Create();
82 Aes.Mode = CipherMode.CBC;
83 Aes.Padding = PaddingMode.PKCS7;
86 using ICryptoTransform Decryptor = Aes.CreateDecryptor(this.
Key, this.
IV);
88 return Decryptor.TransformFinalBlock(Encrypted, 0, Encrypted.Length);
104 byte[] Decrypted = await this.Load();
117 internal async Task<ContentResponse> Scale(
int Width,
int Height)
119 if (!this.
ContentType.StartsWith(
"image/", StringComparison.OrdinalIgnoreCase))
122 byte[] Original = await this.Load();
128 if (!(Decoded.
Decoded is SKImage Image))
131 double ScaleX = ((double)
Width) / Image.Width;
132 double ScaleY = ((double)
Height) / Image.Height;
133 double Scale = Math.Min(ScaleX, ScaleY);
134 int W = (int)(Image.Width * Scale + 0.5);
135 int H = (int)(Image.Height * Scale + 0.5);
137 using SKSurface Surface = SKSurface.Create(
new SKImageInfo(W, H, SKImageInfo.PlatformColorType, SKAlphaType.Premul));
139 SKCanvas Canvas = Surface.Canvas;
140 SKPaint Paint =
new SKPaint()
145 SKSamplingOptions Options =
new SKSamplingOptions(SKCubicResampler.Mitchell);
147 Canvas.DrawImage(Image,
new SKRect(0, 0, W, H), Options, Paint);
149 using SKImage ScaledImage = Surface.Snapshot();
Contains information about a response to a content request.
bool HasError
If an error occurred.
object Decoded
Decoded object.
Static class managing encoding and decoding of internet content.
static Task< ContentResponse > EncodeAsync(object Object, Encoding Encoding, params string[] AcceptedContentTypes)
Encodes an object.
static Task< ContentResponse > DecodeAsync(string ContentType, byte[] Data, Encoding Encoding, KeyValuePair< string, string >[] Fields, Uri BaseUri)
Decodes an object.
Represents an HTTP request.
HttpRequestHeader Header
Request header.
Represets a response of an HTTP client request.
async Task SendResponse()
Sends the response back to the client. If the resource is synchronous, there's no need to call this m...
void SetHeader(string FieldName, string Value)
Sets a custom header field value.
Task Return(Exception ex)
Returns an error to the client.
If the client has performed a conditional GET request and access is allowed, but the document has not...
static async Task< byte[]> ReadAllBytesAsync(string FileName)
Reads a binary file asynchronously.
Stores the contents of an attachment of a Quick-Login identity.
byte[] IV
AES-256 IV to use to decrypt file.
string FileName
File name of encrypted attachment.
QuickLoginAttachment()
Stores the contents of an attachment of a Quick-Login identity.
int? Height
Optional height restriction
string ETag
ETag value of content.
string AttachmentId
Attachment ID
byte[] Key
AES-256 key to use to decrypt file.
int? Width
Optional width restriction
string ContentType
Content-Type of attachment.