mirror of
https://github.com/bitwarden/server
synced 2025-12-19 17:53:44 +00:00
Changed all C# control flow block statements to include space between keyword and open paren
This commit is contained in:
@@ -14,12 +14,12 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(Kdf.HasValue && KdfIterations.HasValue)
|
||||
if (Kdf.HasValue && KdfIterations.HasValue)
|
||||
{
|
||||
switch(Kdf.Value)
|
||||
switch (Kdf.Value)
|
||||
{
|
||||
case KdfType.PBKDF2_SHA256:
|
||||
if(KdfIterations.Value < 5000 || KdfIterations.Value > 2_000_000)
|
||||
if (KdfIterations.Value < 5000 || KdfIterations.Value > 2_000_000)
|
||||
{
|
||||
yield return new ValidationResult("KDF iterations must be between 5000 and 2000000.");
|
||||
}
|
||||
|
||||
@@ -11,12 +11,12 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public User ToUser(User existingUser)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(existingUser.PublicKey) && !string.IsNullOrWhiteSpace(PublicKey))
|
||||
if (string.IsNullOrWhiteSpace(existingUser.PublicKey) && !string.IsNullOrWhiteSpace(PublicKey))
|
||||
{
|
||||
existingUser.PublicKey = PublicKey;
|
||||
}
|
||||
|
||||
if(string.IsNullOrWhiteSpace(existingUser.PrivateKey))
|
||||
if (string.IsNullOrWhiteSpace(existingUser.PrivateKey))
|
||||
{
|
||||
existingUser.PrivateKey = EncryptedPrivateKey;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace Bit.Core.Models.Api
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
var creditType = PaymentMethodType.HasValue && PaymentMethodType.Value == Enums.PaymentMethodType.Credit;
|
||||
if(string.IsNullOrWhiteSpace(PaymentToken) && !creditType && License == null)
|
||||
if (string.IsNullOrWhiteSpace(PaymentToken) && !creditType && License == null)
|
||||
{
|
||||
yield return new ValidationResult("Payment token or license is required.");
|
||||
}
|
||||
|
||||
@@ -37,12 +37,12 @@ namespace Bit.Core.Models.Api
|
||||
KdfIterations = KdfIterations.GetValueOrDefault(5000)
|
||||
};
|
||||
|
||||
if(Key != null)
|
||||
if (Key != null)
|
||||
{
|
||||
user.Key = Key;
|
||||
}
|
||||
|
||||
if(Keys != null)
|
||||
if (Keys != null)
|
||||
{
|
||||
Keys.ToUser(user);
|
||||
}
|
||||
@@ -52,12 +52,12 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(Kdf.HasValue && KdfIterations.HasValue)
|
||||
if (Kdf.HasValue && KdfIterations.HasValue)
|
||||
{
|
||||
switch(Kdf.Value)
|
||||
switch (Kdf.Value)
|
||||
{
|
||||
case KdfType.PBKDF2_SHA256:
|
||||
if(KdfIterations.Value < 5000 || KdfIterations.Value > 1_000_000)
|
||||
if (KdfIterations.Value < 5000 || KdfIterations.Value > 1_000_000)
|
||||
{
|
||||
yield return new ValidationResult("KDF iterations must be between 5000 and 1000000.");
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(StorageGbAdjustment == 0)
|
||||
if (StorageGbAdjustment == 0)
|
||||
{
|
||||
yield return new ValidationResult("Storage adjustment cannot be 0.",
|
||||
new string[] { nameof(StorageGbAdjustment) });
|
||||
|
||||
@@ -33,16 +33,16 @@ namespace Bit.Core.Models.Api
|
||||
};
|
||||
|
||||
var posData = string.Empty;
|
||||
if(UserId.HasValue)
|
||||
if (UserId.HasValue)
|
||||
{
|
||||
posData = "userId:" + UserId.Value;
|
||||
}
|
||||
else if(OrganizationId.HasValue)
|
||||
else if (OrganizationId.HasValue)
|
||||
{
|
||||
posData = "organizationId:" + OrganizationId.Value;
|
||||
}
|
||||
|
||||
if(Credit)
|
||||
if (Credit)
|
||||
{
|
||||
posData += ",accountCredit:1";
|
||||
inv.ItemDesc = "Bitwarden Account Credit";
|
||||
@@ -58,7 +58,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(!UserId.HasValue && !OrganizationId.HasValue)
|
||||
if (!UserId.HasValue && !OrganizationId.HasValue)
|
||||
{
|
||||
yield return new ValidationResult("User or Ooganization is required.");
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public Cipher ToCipher(Cipher existingCipher)
|
||||
{
|
||||
switch(existingCipher.Type)
|
||||
switch (existingCipher.Type)
|
||||
{
|
||||
case CipherType.Login:
|
||||
var loginObj = JObject.FromObject(new CipherLoginData(this),
|
||||
@@ -90,29 +90,29 @@ namespace Bit.Core.Models.Api
|
||||
var hasAttachments2 = (Attachments2?.Count ?? 0) > 0;
|
||||
var hasAttachments = (Attachments?.Count ?? 0) > 0;
|
||||
|
||||
if(!hasAttachments2 && !hasAttachments)
|
||||
if (!hasAttachments2 && !hasAttachments)
|
||||
{
|
||||
return existingCipher;
|
||||
}
|
||||
|
||||
var attachments = existingCipher.GetAttachments();
|
||||
if((attachments?.Count ?? 0) == 0)
|
||||
if ((attachments?.Count ?? 0) == 0)
|
||||
{
|
||||
return existingCipher;
|
||||
}
|
||||
|
||||
if(hasAttachments2)
|
||||
if (hasAttachments2)
|
||||
{
|
||||
foreach(var attachment in attachments.Where(a => Attachments2.ContainsKey(a.Key)))
|
||||
foreach (var attachment in attachments.Where(a => Attachments2.ContainsKey(a.Key)))
|
||||
{
|
||||
var attachment2 = Attachments2[attachment.Key];
|
||||
attachment.Value.FileName = attachment2.FileName;
|
||||
attachment.Value.Key = attachment2.Key;
|
||||
}
|
||||
}
|
||||
else if(hasAttachments)
|
||||
else if (hasAttachments)
|
||||
{
|
||||
foreach(var attachment in attachments.Where(a => Attachments.ContainsKey(a.Key)))
|
||||
foreach (var attachment in attachments.Where(a => Attachments.ContainsKey(a.Key)))
|
||||
{
|
||||
attachment.Value.FileName = Attachments[attachment.Key];
|
||||
attachment.Value.Key = null;
|
||||
@@ -125,7 +125,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public Cipher ToOrganizationCipher()
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(OrganizationId))
|
||||
if (string.IsNullOrWhiteSpace(OrganizationId))
|
||||
{
|
||||
throw new ArgumentNullException(nameof(OrganizationId));
|
||||
}
|
||||
@@ -162,7 +162,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(!string.IsNullOrWhiteSpace(Cipher.OrganizationId) && (!CollectionIds?.Any() ?? true))
|
||||
if (!string.IsNullOrWhiteSpace(Cipher.OrganizationId) && (!CollectionIds?.Any() ?? true))
|
||||
{
|
||||
yield return new ValidationResult("You must select at least one collection.",
|
||||
new string[] { nameof(CollectionIds) });
|
||||
@@ -179,13 +179,13 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(Cipher.OrganizationId))
|
||||
if (string.IsNullOrWhiteSpace(Cipher.OrganizationId))
|
||||
{
|
||||
yield return new ValidationResult("Cipher OrganizationId is required.",
|
||||
new string[] { nameof(Cipher.OrganizationId) });
|
||||
}
|
||||
|
||||
if(!CollectionIds?.Any() ?? true)
|
||||
if (!CollectionIds?.Any() ?? true)
|
||||
{
|
||||
yield return new ValidationResult("You must select at least one collection.",
|
||||
new string[] { nameof(CollectionIds) });
|
||||
@@ -221,7 +221,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(!Ciphers?.Any() ?? true)
|
||||
if (!Ciphers?.Any() ?? true)
|
||||
{
|
||||
yield return new ValidationResult("You must select at least one cipher.",
|
||||
new string[] { nameof(Ciphers) });
|
||||
@@ -230,27 +230,27 @@ namespace Bit.Core.Models.Api
|
||||
{
|
||||
var allHaveIds = true;
|
||||
var organizationIds = new HashSet<string>();
|
||||
foreach(var c in Ciphers)
|
||||
foreach (var c in Ciphers)
|
||||
{
|
||||
organizationIds.Add(c.OrganizationId);
|
||||
if(allHaveIds)
|
||||
if (allHaveIds)
|
||||
{
|
||||
allHaveIds = !(!c.Id.HasValue || string.IsNullOrWhiteSpace(c.OrganizationId));
|
||||
}
|
||||
}
|
||||
|
||||
if(!allHaveIds)
|
||||
if (!allHaveIds)
|
||||
{
|
||||
yield return new ValidationResult("All Ciphers must have an Id and OrganizationId.",
|
||||
new string[] { nameof(Ciphers) });
|
||||
}
|
||||
else if(organizationIds.Count != 1)
|
||||
else if (organizationIds.Count != 1)
|
||||
{
|
||||
yield return new ValidationResult("All ciphers must be for the same organization.");
|
||||
}
|
||||
}
|
||||
|
||||
if(!CollectionIds?.Any() ?? true)
|
||||
if (!CollectionIds?.Any() ?? true)
|
||||
{
|
||||
yield return new ValidationResult("You must select at least one collection.",
|
||||
new string[] { nameof(CollectionIds) });
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(PaymentMethodType != Enums.PaymentMethodType.AppleInApp)
|
||||
if (PaymentMethodType != Enums.PaymentMethodType.AppleInApp)
|
||||
{
|
||||
yield return new ValidationResult("Not a supported in-app purchase payment method.",
|
||||
new string[] { nameof(PaymentMethodType) });
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(Email) && !Deleted)
|
||||
if (string.IsNullOrWhiteSpace(Email) && !Deleted)
|
||||
{
|
||||
yield return new ValidationResult("Email is required for enabled users.", new string[] { nameof(Email) });
|
||||
}
|
||||
|
||||
@@ -53,11 +53,11 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(PlanType != PlanType.Free && string.IsNullOrWhiteSpace(PaymentToken))
|
||||
if (PlanType != PlanType.Free && string.IsNullOrWhiteSpace(PaymentToken))
|
||||
{
|
||||
yield return new ValidationResult("Payment required.", new string[] { nameof(PaymentToken) });
|
||||
}
|
||||
if(PlanType != PlanType.Free && !PaymentMethodType.HasValue)
|
||||
if (PlanType != PlanType.Free && !PaymentMethodType.HasValue)
|
||||
{
|
||||
yield return new ValidationResult("Payment method type required.",
|
||||
new string[] { nameof(PaymentMethodType) });
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(SeatAdjustment == 0)
|
||||
if (SeatAdjustment == 0)
|
||||
{
|
||||
yield return new ValidationResult("Seat adjustment cannot be 0.", new string[] { nameof(SeatAdjustment) });
|
||||
}
|
||||
|
||||
@@ -17,26 +17,26 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(!Emails.Any())
|
||||
if (!Emails.Any())
|
||||
{
|
||||
yield return new ValidationResult("An email is required.");
|
||||
}
|
||||
|
||||
if(Emails.Count() > 20)
|
||||
if (Emails.Count() > 20)
|
||||
{
|
||||
yield return new ValidationResult("You can only invite up to 20 users at a time.");
|
||||
}
|
||||
|
||||
var attr = new EmailAddressAttribute();
|
||||
for(var i = 0; i < Emails.Count(); i++)
|
||||
for (var i = 0; i < Emails.Count(); i++)
|
||||
{
|
||||
var email = Emails.ElementAt(i);
|
||||
if(!attr.IsValid(email) || email.Contains(" ") || email.Contains("<"))
|
||||
if (!attr.IsValid(email) || email.Contains(" ") || email.Contains("<"))
|
||||
{
|
||||
yield return new ValidationResult($"Email #{i + 1} is not valid.",
|
||||
new string[] { nameof(Emails) });
|
||||
}
|
||||
else if(email.Length > 50)
|
||||
else if (email.Length > 50)
|
||||
{
|
||||
yield return new ValidationResult($"Email #{i + 1} is longer than 50 characters.",
|
||||
new string[] { nameof(Emails) });
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(UserId) && string.IsNullOrWhiteSpace(OrganizationId))
|
||||
if (string.IsNullOrWhiteSpace(UserId) && string.IsNullOrWhiteSpace(OrganizationId))
|
||||
{
|
||||
yield return new ValidationResult($"{nameof(UserId)} or {nameof(OrganizationId)} is required.");
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ namespace Bit.Core.Models.Api
|
||||
public User ToUser(User extistingUser)
|
||||
{
|
||||
var providers = extistingUser.GetTwoFactorProviders();
|
||||
if(providers == null)
|
||||
if (providers == null)
|
||||
{
|
||||
providers = new Dictionary<TwoFactorProviderType, TwoFactorProvider>();
|
||||
}
|
||||
else if(providers.ContainsKey(TwoFactorProviderType.Authenticator))
|
||||
else if (providers.ContainsKey(TwoFactorProviderType.Authenticator))
|
||||
{
|
||||
providers.Remove(TwoFactorProviderType.Authenticator);
|
||||
}
|
||||
@@ -52,11 +52,11 @@ namespace Bit.Core.Models.Api
|
||||
public User ToUser(User extistingUser)
|
||||
{
|
||||
var providers = extistingUser.GetTwoFactorProviders();
|
||||
if(providers == null)
|
||||
if (providers == null)
|
||||
{
|
||||
providers = new Dictionary<TwoFactorProviderType, TwoFactorProvider>();
|
||||
}
|
||||
else if(providers.ContainsKey(TwoFactorProviderType.Duo))
|
||||
else if (providers.ContainsKey(TwoFactorProviderType.Duo))
|
||||
{
|
||||
providers.Remove(TwoFactorProviderType.Duo);
|
||||
}
|
||||
@@ -78,11 +78,11 @@ namespace Bit.Core.Models.Api
|
||||
public Organization ToOrganization(Organization extistingOrg)
|
||||
{
|
||||
var providers = extistingOrg.GetTwoFactorProviders();
|
||||
if(providers == null)
|
||||
if (providers == null)
|
||||
{
|
||||
providers = new Dictionary<TwoFactorProviderType, TwoFactorProvider>();
|
||||
}
|
||||
else if(providers.ContainsKey(TwoFactorProviderType.OrganizationDuo))
|
||||
else if (providers.ContainsKey(TwoFactorProviderType.OrganizationDuo))
|
||||
{
|
||||
providers.Remove(TwoFactorProviderType.OrganizationDuo);
|
||||
}
|
||||
@@ -103,7 +103,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(!Host.StartsWith("api-") || !Host.EndsWith(".duosecurity.com"))
|
||||
if (!Host.StartsWith("api-") || !Host.EndsWith(".duosecurity.com"))
|
||||
{
|
||||
yield return new ValidationResult("Host is invalid.", new string[] { nameof(Host) });
|
||||
}
|
||||
@@ -123,11 +123,11 @@ namespace Bit.Core.Models.Api
|
||||
public User ToUser(User extistingUser)
|
||||
{
|
||||
var providers = extistingUser.GetTwoFactorProviders();
|
||||
if(providers == null)
|
||||
if (providers == null)
|
||||
{
|
||||
providers = new Dictionary<TwoFactorProviderType, TwoFactorProvider>();
|
||||
}
|
||||
else if(providers.ContainsKey(TwoFactorProviderType.YubiKey))
|
||||
else if (providers.ContainsKey(TwoFactorProviderType.YubiKey))
|
||||
{
|
||||
providers.Remove(TwoFactorProviderType.YubiKey);
|
||||
}
|
||||
@@ -151,7 +151,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
private string FormatKey(string keyValue)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(keyValue))
|
||||
if (string.IsNullOrWhiteSpace(keyValue))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -161,33 +161,33 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(Key1) && string.IsNullOrWhiteSpace(Key2) && string.IsNullOrWhiteSpace(Key3) &&
|
||||
if (string.IsNullOrWhiteSpace(Key1) && string.IsNullOrWhiteSpace(Key2) && string.IsNullOrWhiteSpace(Key3) &&
|
||||
string.IsNullOrWhiteSpace(Key4) && string.IsNullOrWhiteSpace(Key5))
|
||||
{
|
||||
yield return new ValidationResult("A key is required.", new string[] { nameof(Key1) });
|
||||
}
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(Key1) && Key1.Length < 12)
|
||||
if (!string.IsNullOrWhiteSpace(Key1) && Key1.Length < 12)
|
||||
{
|
||||
yield return new ValidationResult("Key 1 in invalid.", new string[] { nameof(Key1) });
|
||||
}
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(Key2) && Key2.Length < 12)
|
||||
if (!string.IsNullOrWhiteSpace(Key2) && Key2.Length < 12)
|
||||
{
|
||||
yield return new ValidationResult("Key 2 in invalid.", new string[] { nameof(Key2) });
|
||||
}
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(Key3) && Key3.Length < 12)
|
||||
if (!string.IsNullOrWhiteSpace(Key3) && Key3.Length < 12)
|
||||
{
|
||||
yield return new ValidationResult("Key 3 in invalid.", new string[] { nameof(Key3) });
|
||||
}
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(Key4) && Key4.Length < 12)
|
||||
if (!string.IsNullOrWhiteSpace(Key4) && Key4.Length < 12)
|
||||
{
|
||||
yield return new ValidationResult("Key 4 in invalid.", new string[] { nameof(Key4) });
|
||||
}
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(Key5) && Key5.Length < 12)
|
||||
if (!string.IsNullOrWhiteSpace(Key5) && Key5.Length < 12)
|
||||
{
|
||||
yield return new ValidationResult("Key 5 in invalid.", new string[] { nameof(Key5) });
|
||||
}
|
||||
@@ -204,11 +204,11 @@ namespace Bit.Core.Models.Api
|
||||
public User ToUser(User extistingUser)
|
||||
{
|
||||
var providers = extistingUser.GetTwoFactorProviders();
|
||||
if(providers == null)
|
||||
if (providers == null)
|
||||
{
|
||||
providers = new Dictionary<TwoFactorProviderType, TwoFactorProvider>();
|
||||
}
|
||||
else if(providers.ContainsKey(TwoFactorProviderType.Email))
|
||||
else if (providers.ContainsKey(TwoFactorProviderType.Email))
|
||||
{
|
||||
providers.Remove(TwoFactorProviderType.Email);
|
||||
}
|
||||
@@ -237,7 +237,7 @@ namespace Bit.Core.Models.Api
|
||||
|
||||
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||
{
|
||||
if(!Id.HasValue || Id < 0 || Id > 5)
|
||||
if (!Id.HasValue || Id < 0 || Id > 5)
|
||||
{
|
||||
yield return new ValidationResult("Invalid Key Id", new string[] { nameof(Id) });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user