public TaskAttachment(String type, String name) { ArgumentUtility.CheckStringForNullOrEmpty(type, "type"); ArgumentUtility.CheckStringForNullOrEmpty(name, "name"); this.Type = type; this.Name = name; }
public static void AddMultiple <T>(this IList <KeyValuePair <String, String> > collection, String key, IEnumerable <T> values, Func <T, String> convert) { ArgumentUtility.CheckForNull(collection, "collection"); ArgumentUtility.CheckStringForNullOrEmpty(key, "name"); if (convert == null) { convert = (val) => val.ToString(); } if (values != null && values.Any()) { StringBuilder newValue = new StringBuilder(); KeyValuePair <String, String> matchingKvp = collection.FirstOrDefault(kvp => kvp.Key.Equals(key)); if (matchingKvp.Key == key) { collection.Remove(matchingKvp); newValue.Append(matchingKvp.Value); } foreach (var value in values) { if (newValue.Length > 0) { newValue.Append(","); } newValue.Append(convert(value)); } collection.Add(new KeyValuePair <String, String>(key, newValue.ToString())); } }
private static JsonWebToken Create(string issuer, string audience, DateTime validFrom, DateTime validTo, DateTime issuedAt, IEnumerable <Claim> additionalClaims, JsonWebToken actor, string actorToken, VssSigningCredentials credentials, bool allowExpiredCertificate) { ArgumentUtility.CheckStringForNullOrEmpty(issuer, nameof(issuer)); ArgumentUtility.CheckStringForNullOrEmpty(audience, nameof(audience)); // Audience isn't actually required... validFrom = validFrom == default(DateTime) ? DateTime.UtcNow : validFrom.ToUniversalTime(); validTo = validTo == default(DateTime) ? DateTime.UtcNow + TimeSpan.FromSeconds(DefaultLifetime) : validTo.ToUniversalTime(); //issuedAt is optional, and breaks certain scenarios if it is present, and breaks others if it is not. //so only include it if it is explicitly set. issuedAt = issuedAt == default(DateTime) ? default(DateTime) : issuedAt.ToUniversalTime(); JWTHeader header = GetHeader(credentials, allowExpiredCertificate); JWTPayload payload = new JWTPayload(additionalClaims) { Issuer = issuer, Audience = audience, ValidFrom = validFrom, ValidTo = validTo, IssuedAt = issuedAt }; if (actor != null) { payload.Actor = actor; } else if (actorToken != null) { payload.ActorToken = actorToken; } byte[] signature = GetSignature(header, payload, header.Algorithm, credentials); return(new JsonWebToken(header, payload, signature)); }
internal TaskAttachment(String type, String name, ReferenceLinks links) { ArgumentUtility.CheckStringForNullOrEmpty(type, "type"); ArgumentUtility.CheckStringForNullOrEmpty(name, "name"); this.Type = type; this.Name = name; this.m_links = links; }
/// <summary> /// Initializes a new <c>VssOAuthAccessToken</c> instance with the specified value and expiration time. /// </summary> /// <param name="value">The value of the access token, encoded as a string</param> /// <param name="validTo">The date and time when this token is no longer valid</param> public VssOAuthAccessToken( String value, DateTime validTo) { ArgumentUtility.CheckStringForNullOrEmpty(value, nameof(value)); m_value = value; m_validTo = validTo; }
public static JsonWebToken Create(string jwtEncodedString) { ArgumentUtility.CheckStringForNullOrEmpty(jwtEncodedString, nameof(jwtEncodedString)); JValue value = new JValue(jwtEncodedString); return(value.ToObject <JsonWebToken>()); }
//use this method to instantiate the token with user information public static JsonWebToken Create(string issuer, string audience, DateTime validFrom, DateTime validTo, IEnumerable <Claim> additionalClaims, string actorToken) { //if you are calling this version of the method additionalClaims and actor cannot be null ArgumentUtility.CheckForNull(additionalClaims, nameof(additionalClaims)); ArgumentUtility.CheckStringForNullOrEmpty(actorToken, nameof(actorToken)); return(Create(issuer, audience, validFrom, validTo, default(DateTime), additionalClaims, null, actorToken, null, allowExpiredCertificate: false)); }
/// <summary> /// Validation helper for validating all property strings. /// </summary> /// <param name="propertyString"></param> /// <param name="maxSize"></param> /// <param name="argumentName"></param> private static void ValidatePropertyString(String propertyString, Int32 maxSize, String argumentName) { ArgumentUtility.CheckStringForNullOrEmpty(propertyString, argumentName); if (propertyString.Length > maxSize) { throw new VssPropertyValidationException(argumentName, CommonResources.PropertyArgumentExceededMaximumSizeAllowed(argumentName, maxSize)); } ArgumentUtility.CheckStringForInvalidCharacters(propertyString, argumentName, true); }
/// <summary> /// Used for Testing Only /// </summary> /// <param name="typeName"></param> /// <param name="type"></param> internal void RegisterExtensibleType( String typeName, Type type) { ArgumentUtility.CheckStringForNullOrEmpty(typeName, "typeName"); ArgumentUtility.CheckForNull(type, "type"); m_extensibleServiceTypes[typeName] = type; }
public static void ValidateContainerName(string containerName) { ArgumentUtility.CheckStringForNullOrEmpty(containerName, "containerName", true); ArgumentUtility.CheckStringForInvalidCharacters(containerName, "containerName"); if (containerName.Contains(Semicolon)) { throw new ArgumentException("Container name cannot contain the character ';'", containerName); } }
protected VssOAuthClientCredential( VssOAuthClientCredentialType type, String clientId) { ArgumentUtility.CheckStringForNullOrEmpty(clientId, nameof(clientId)); m_type = type; m_clientId = clientId; }
public static void ValidateAttributeName(string attributeName) { ArgumentUtility.CheckStringForNullOrEmpty(attributeName, "attributeName", true); ArgumentUtility.CheckStringForInvalidCharacters(attributeName, "attributeName"); if (attributeName.Contains(Semicolon)) { throw new ArgumentException("Attribute name cannot contain the character ';'", attributeName); } }
internal static T JsonDecode <T>(string encodedString) { ArgumentUtility.CheckStringForNullOrEmpty(encodedString, nameof(encodedString)); byte[] bytes = encodedString.FromBase64StringNoPadding(); string json = Encoding.UTF8.GetString(bytes); return(JsonConvert.DeserializeObject <T>(json, DefaultSerializerSettings)); }
public static Uri AppendQuery(this Uri uri, String name, String value) { ArgumentUtility.CheckForNull(uri, "uri"); ArgumentUtility.CheckStringForNullOrEmpty(name, "name"); ArgumentUtility.CheckStringForNullOrEmpty(value, "value"); StringBuilder stringBuilder = new StringBuilder(uri.Query.TrimStart('?')); AppendSingleQueryValue(stringBuilder, name, value); UriBuilder uriBuilder = new UriBuilder(uri); uriBuilder.Query = stringBuilder.ToString(); return(uriBuilder.Uri); }
public static void AddMultiple <T>(this NameValueCollection collection, String name, IEnumerable <T> values, Func <T, String> convert) { ArgumentUtility.CheckForNull(collection, "collection"); ArgumentUtility.CheckStringForNullOrEmpty(name, "name"); if (convert == null) { convert = (val) => val.ToString(); } if (values != null) { foreach (var value in values) { collection.Add(name, convert(value)); } } }
public static byte[] FromBase64StringNoPadding(this String base64String) { ArgumentUtility.CheckStringForNullOrEmpty(base64String, "base64String"); string s = base64String; s = s.Replace('-', '+'); // 62nd char of encoding s = s.Replace('_', '/'); // 63rd char of encoding switch (s.Length % 4) // Pad with trailing '='s { case 0: break; // No pad chars in this case case 2: s += "=="; break; // Two pad chars case 3: s += "="; break; // One pad char default: throw new ArgumentException(CommonResources.IllegalBase64String(), "base64String"); } return(Convert.FromBase64String(s)); // Standard base64 decoder }
private static void ValidateIssuer(JsonWebToken token, JsonWebTokenValidationParameters parameters) { ArgumentUtility.CheckForNull(token, nameof(token)); ArgumentUtility.CheckForNull(parameters, nameof(parameters)); if (!parameters.ValidateIssuer) { return; } ArgumentUtility.CheckStringForNullOrEmpty(token.Issuer, nameof(token.Issuer)); ArgumentUtility.CheckEnumerableForNullOrEmpty(parameters.ValidIssuers, nameof(parameters.ValidIssuers)); foreach (string issuer in parameters.ValidIssuers) { if (string.Compare(issuer, token.Issuer, StringComparison.OrdinalIgnoreCase) == 0) { return; } } throw new InvalidIssuerException(); //validation exception; }
private static void ValidateAudience(JsonWebToken token, JsonWebTokenValidationParameters parameters) { ArgumentUtility.CheckForNull(token, nameof(token)); ArgumentUtility.CheckForNull(parameters, nameof(parameters)); if (!parameters.ValidateAudience) { return; } ArgumentUtility.CheckStringForNullOrEmpty(token.Audience, nameof(token.Audience)); ArgumentUtility.CheckEnumerableForNullOrEmpty(parameters.AllowedAudiences, nameof(parameters.AllowedAudiences)); foreach (string audience in parameters.AllowedAudiences) { if (string.Compare(audience, token.Audience, StringComparison.OrdinalIgnoreCase) == 0) { return; } } throw new InvalidAudienceException(); //validation exception; }
/// <summary> /// Returns the access mapping for the provided moniker. /// </summary> /// <param name="moniker">The moniker of the access mapping to /// return.</param> /// <returns>The access mapping for the provided moniker or null /// if an access mapping for the moniker doesn't exist..</returns> public AccessMapping GetAccessMapping(String moniker) { ArgumentUtility.CheckStringForNullOrEmpty(moniker, "moniker"); EnsureDiskCacheLoaded(); m_accessLock.EnterReadLock(); try { if (CacheDataExpired) { return(null); } AccessMapping accessMapping; m_accessMappings.TryGetValue(moniker, out accessMapping); return(accessMapping); } finally { m_accessLock.ExitReadLock(); } }
public static void ParseVersion( String version, out Int32 major, out Int32 minor, out Int32 patch, out String semanticVersion) { ArgumentUtility.CheckStringForNullOrEmpty(version, "version"); String[] segments = version.Split(new char[] { '.', '-' }, StringSplitOptions.None); if (segments.Length < 3 || segments.Length > 4) { throw new ArgumentException("wrong number of segments"); } if (!Int32.TryParse(segments[0], out major)) { throw new ArgumentException("major"); } if (!Int32.TryParse(segments[1], out minor)) { throw new ArgumentException("minor"); } if (!Int32.TryParse(segments[2], out patch)) { throw new ArgumentException("patch"); } semanticVersion = null; if (segments.Length == 4) { semanticVersion = segments[3]; } }
public ValueSecret(String value) { ArgumentUtility.CheckStringForNullOrEmpty(value, nameof(value)); m_value = value; }
public RegexSecret(String pattern) { ArgumentUtility.CheckStringForNullOrEmpty(pattern, nameof(pattern)); m_pattern = pattern; m_regex = new Regex(pattern); }
public TaskLog(String path) { ArgumentUtility.CheckStringForNullOrEmpty(path, "path"); this.Path = path; }