/// <summary> /// Try and parse the final server message. /// </summary> /// <param name="message">Message to parse.</param> /// <param name="finalMessage"><see cref="ServerFinalMessage"/> instance of the message.</param> /// <returns>true if the parsing succeeded; otherwise false.</returns> public static bool TryParse(string message, out ServerFinalMessage finalMessage) { finalMessage = new ServerFinalMessage(); try { var attributes = ScramAttribute.ParseAll(message); if (!attributes.OfType <ServerSignatureAttribute>().Any()) { return(false); } foreach (var attribute in attributes) { switch (attribute) { case ServerSignatureAttribute a: finalMessage.ServerSignature = a; break; case ErrorAttribute a: return(false); } } } catch (FormatException) { return(false); } return(true); }
public void When_CreatedByParsing_ValueShouldBeValid() { var attribute = ScramAttribute.Parse("v=rmF9pqV8S7suAoZWja4dJRkFsKQ="); var result = new ServerSignatureAttribute("rmF9pqV8S7suAoZWja4dJRkFsKQ="); attribute.ShouldBe(result); }
public void When_ThereAreMoreParts_ShouldThrowAnException() { Should.Throw <FormatException>(() => { var _ = ScramAttribute.Parse("value"); }); }
public void When_CreatingTwoAttributes_TheHashCodesShouldBeEqual() { var first = ScramAttribute.Parse("v=rmF9pqV8S7suAoZWja4dJRkFsKQ="); var second = new ServerSignatureAttribute("rmF9pqV8S7suAoZWja4dJRkFsKQ="); first.GetHashCode().ShouldBe(second.GetHashCode()); }
public void When_NameIsTwoCharacters_ShouldThrowAnException() { Should.Throw <FormatException>(() => { var _ = ScramAttribute.Parse("bh=name"); }); }
/// <summary> /// Parse the first server message. /// </summary> /// <param name="message">Message to parse.</param> /// <param name="firstMessage"><see cref="ServerFirstMessage"/> instance of the message.</param> /// <returns>true if parsing was successful; otherwise false.</returns> public static bool TryParse(string message, out ServerFirstMessage firstMessage) { firstMessage = new ServerFirstMessage(); try { var attributes = ScramAttribute.ParseAll(message); if (!attributes.OfType <IterationsAttribute>().Any() || !attributes.OfType <NonceAttribute>().Any() || !attributes.OfType <SaltAttribute>().Any()) { return(false); } foreach (var attribute in attributes) { switch (attribute) { case IterationsAttribute a: firstMessage.Iterations = a; break; case NonceAttribute a: firstMessage.Nonce = a; break; case SaltAttribute a: firstMessage.Salt = a; break; case ErrorAttribute a: return(false); } } } catch (FormatException) { return(false); } return(true); }
public static ServerFinalMessage ParseResponse(string response) { var parts = ScramAttribute.ParseAll(response.Split(',')); var error = parts.OfType <ErrorAttribute>().ToList(); if (error.Any()) { throw new InvalidOperationException(); } var signature = parts.OfType <ServerSignatureAttribute>().ToList(); if (!signature.Any()) { throw new InvalidOperationException(); } return(new ServerFinalMessage(signature.First())); }
public static ServerFirstMessage ParseResponse(string response) { var parts = ScramAttribute.ParseAll(response.Split(',')); var errors = parts.OfType <ErrorAttribute>(); if (errors.Any()) { throw new InvalidOperationException(); } var iterations = parts.OfType <IterationsAttribute>().ToList(); var nonces = parts.OfType <NonceAttribute>().ToList(); var salts = parts.OfType <SaltAttribute>().ToList(); if (!iterations.Any() || !nonces.Any() || !salts.Any()) { throw new InvalidOperationException(); } return(new ServerFirstMessage(iterations.First(), nonces.First(), salts.First())); }
public void When_ParsingAnUnknownAttribute_ShouldBeValid() { var attribute = ScramAttribute.Parse("h=name"); attribute.ShouldBeOfType <UnknownAttribute>(); }
public void When_ParsingAClientProofAttribute_ShouldBeValid() { var attribute = ScramAttribute.Parse("p=v0X8v3Bz2T0CJGbJQyF0X+HI4Ts="); attribute.ShouldBeOfType <ClientProofAttribute>(); }
public void When_ParsingAChannelAttribute_ShouldBeValid() { var attribute = ScramAttribute.Parse("c=biws"); attribute.ShouldBeOfType <ChannelAttribute>(); }
public void When_ParsingAUserAttribute_ShouldBeValid() { var attribute = ScramAttribute.Parse("n=name"); attribute.ShouldBeOfType <UserAttribute>(); }
public void When_ParsingAnAuthorizationAttribute_ShouldBeValid() { var attribute = ScramAttribute.Parse("a=name"); attribute.ShouldBeOfType <AuthorizationIdentityAttribute>(); }
public void When_ChannelIsNotSupported_ShouldBeValid() { var _ = ScramAttribute.ParseAll("n,,n=name"); }
public void When_AttributeIsNotNull_ShouldBeEqual() { var attribute = ScramAttribute.Parse("v=rmF9pqV8S7suAoZWja4dJRkFsKQ="); Assert.False(attribute.Equals(null)); }
public ServerFirstMessage(int iterations, string nonce, byte[] salt) { Iterations = new IterationsAttribute(iterations); Nonce = new NonceAttribute(nonce); Salt = new SaltAttribute(salt); }
private ServerFirstMessage(IterationsAttribute iterations, NonceAttribute nonce, SaltAttribute salt) { Iterations = iterations; Nonce = nonce; Salt = salt; }
public void When_AttributeIsComparedToItself_ShouldBeEqual() { var attribute = ScramAttribute.Parse("v=rmF9pqV8S7suAoZWja4dJRkFsKQ="); Assert.True(attribute.Equals(attribute)); }