1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 08:02:49 -05:00

move all models into core

This commit is contained in:
Kyle Spearrin
2017-03-08 21:55:08 -05:00
parent bd0c960e9f
commit 8bcd4e0463
60 changed files with 64 additions and 64 deletions

View File

@ -1,61 +0,0 @@
using System;
using System.ComponentModel.DataAnnotations;
namespace Bit.Api.Utilities
{
/// <summary>
/// Validates a string that is in encrypted form: "b64iv=|b64ct="
/// </summary>
public class EncryptedStringAttribute : ValidationAttribute
{
public EncryptedStringAttribute()
: base("{0} is not a valid encrypted string.")
{ }
public override bool IsValid(object value)
{
if(value == null)
{
return true;
}
try
{
var encString = value?.ToString();
if(string.IsNullOrWhiteSpace(encString))
{
return false;
}
var encStringPieces = encString.Split('|');
if(encStringPieces.Length != 2 && encStringPieces.Length != 3)
{
return false;
}
var iv = Convert.FromBase64String(encStringPieces[0]);
var ct = Convert.FromBase64String(encStringPieces[1]);
if(iv.Length < 1 || ct.Length < 1)
{
return false;
}
if(encStringPieces.Length == 3)
{
var mac = Convert.FromBase64String(encStringPieces[2]);
if(mac.Length < 1)
{
return false;
}
}
}
catch
{
return false;
}
return true;
}
}
}

View File

@ -1,5 +1,5 @@
using System;
using Bit.Api.Models.Response;
using Bit.Core.Models.Api;
using Bit.Core.Exceptions;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;

View File

@ -1,6 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Bit.Api.Models.Response;
using Bit.Core.Models.Api;
using System.Linq;
namespace Bit.Api.Utilities