public SchemaValidationResult Validate(object model) { var data = model as QueryRequest; var result = new SchemaValidationResult(); var location = "QueryRequest"; result.MissingCheck($"Issuer", data.Issuer, location); result.MissingCheck($"Issuer.Type", data.Issuer.Type, location); result.MaxRangeCheck($"Issuer.Type", data.Issuer.Type, location, SchemaValidationResult.DEFAULT_MAX_LENGTH); var identityValidator = _validatorFactory.GetIdentityValidator(data.Issuer); identityValidator.Validate("Issuer", data.Issuer, data, "QueryRequest", result); result.MaxRangeCheck($"Types", data.Types.Count, location, 127); var index = 0; foreach (var type in data.Types) { result.MaxRangeCheck($"Types[{index}]", type, location, 127); index++; } result.MaxRangeCheck($"Subjects", data.Subjects.Count, location, 1024); index = 0; foreach (var subject in data.Subjects) { result.MaxRangeCheck($"Subjects[{index}]", subject, location, 127); index++; } return(result); }
public void Validate(string name, Identity identity, object source, string location, SchemaValidationResult result) { var claim = source as Claim; result.MaxRangeCheck($"{name} Id", identity.Id, location, 40); if (claim != null) { result.MissingCheck($"{name} Proof", identity.Id, location); result.MaxRangeCheck($"{name} Proof", identity.Proof, location, SchemaValidationResult.DEFAULT_TITLE_LENGTH); } // TODO: Properly validate Id var regex = new Regex(@"^[13nmD][a-km-zA-HJ-NP-Z0-9]{26,33}$"); if (!regex.IsMatch(identity.Id)) { result.Errors.Add(string.Format(InvalidAddressErrorTemplate, location, $"{name} Id")); return; } if (claim != null) { var message = _claimBinary.GetIdSource(claim).ConvertToBase64(); if (!_derivationSecp256K1PKH.VerifySignatureMessage(message, identity.Proof, identity.Id)) { result.Errors.Add(string.Format(InvalidProofErrorTemplate, location, $"{name} Proof")); } } }
public void Validate(string name, Identity identity, object source, string location, SchemaValidationResult result) { result.MaxRangeCheck($"{name} Id", identity.Id, location, SchemaValidationResult.DEFAULT_TITLE_LENGTH); result.MaxRangeCheck($"{name} Proof", identity.Proof, location, 0); if (!Uri.IsWellFormedUriString(identity.Id, UriKind.Absolute)) { result.Errors.Add(string.Format(NotUriErrorTemplate, location, $"{name}.Id")); } }
public void Validate(string name, Identity identity, object source, string location, SchemaValidationResult result) { result.MaxRangeCheck($"{name} Id", identity.Id, location, SchemaValidationResult.DEFAULT_MAX_LENGTH); result.MaxRangeCheck($"{name} Proof", identity.Proof, location, 0); var regex = new Regex(@"^\w+$"); // ^[0-9]+$ if (!regex.IsMatch(identity.Id)) { result.Errors.Add(string.Format(NotAlphaNumericErrorTemplate, location, $"{name}.Id")); } }
public void Validate(string name, Identity identity, object source, string location, SchemaValidationResult result) { result.MaxRangeCheck($"{name} Id", identity.Id, location, SchemaValidationResult.DEFAULT_TITLE_LENGTH); result.MaxRangeCheck($"{name} Proof", identity.Proof, location, 0); var regex = new Regex(@"^[13nmD][a-km-zA-HJ-NP-Z0-9]{26,33}$"); if (!regex.IsMatch(identity.Id)) { result.Errors.Add(string.Format(InvalidAddressErrorTemplate, location, $"{name} Id")); return; } }
private void ValidateClaim(int claimIndex, Claim claim, SchemaValidationResult result) { var location = $"Claim Index: {claimIndex} - "; result.MaxRangeCheck("Id", claim.Id, location, ID_MAX_LENGTH); result.MaxRangeCheck("Type", claim.Type, location, TYPE_MAX_LENGTH); result.MaxRangeCheck("Value", claim.Value, location, CLAIM_MAX_LENGTH); result.MaxRangeCheck("Note", claim.Note, location, NOTE_MAX_LENGTH); ValidateIssuer(claim, location); ValidateSubject(claim, location); ValidateScope(claim, location); ValidateTimestamps(claim.Timestamps, location); }
public void Validate(string name, Identity identity, object source, string location, SchemaValidationResult result) { result.MaxRangeCheck($"{name} Id", identity.Id, location, 40); result.NotEmptyCheck($"{name} Proof", identity.Proof, location); result.MaxRangeCheck($"{name} Proof", identity.Proof, location, 1024); // TODO: Properly validate Id var regex = new Regex(@"^[13nmD][a-km-zA-HJ-NP-Z0-9]{26,33}$"); if (!regex.IsMatch(identity.Id)) { result.Errors.Add(string.Format(InvalidAddressErrorTemplate, location, $"{name} Id")); return; } }
public SchemaValidationResult Validate(Package package) { result.MaxRangeCheck("Package Type", package.Type, "", TYPE_MAX_LENGTH); result.MaxRangeCheck("Package Id", package.Id, "", ID_MAX_LENGTH); ValidateServer(package); try { var script = _merkleStrategyFactory.GetStrategy(package.Type); var testBuilder = new PackageBuilder(_merkleStrategyFactory, _hashAlgorithmFactory, _packageBinary); var claimIndex = 0; if (package.Claims.Count == 0) { result.MissingCheck("Package claims", "", ""); } foreach (var claim in package.Claims) { testBuilder.AddClaim(claim); ValidateClaim(claimIndex++, claim, result); } if (package.Id != null && package.Id.Length > 0) { testBuilder.Package.Type = package.Type; testBuilder.Package.Created = package.Created; testBuilder.Package.Server = package.Server; var testPackageID = testBuilder.Build().Package.Id; if (testPackageID.Compare(package.Id) != 0) { result.Errors.Add("Package Id is not same as merkle tree root of all claim ID"); } } ValidateTimestamps(package.Timestamps, "Package "); } catch (Exception ex) { result.Errors.Add(ex.Message); } return(result); }
public void Validate(string name, Identity identity, object source, string location, SchemaValidationResult result) { result.MaxRangeCheck($"{name} Id", identity.Id, location, SchemaValidationResult.DEFAULT_MAX_LENGTH); result.MaxRangeCheck($"{name} Proof", identity.Proof, location, 0); }