public void AddCryptoLine(string crypto) { this.SecurityDescriptions.Add(SDPSecurityDescription.Parse(crypto)); }
public static bool TryParse(string cryptoLine, out SDPSecurityDescription securityDescription) { securityDescription = null; if (string.IsNullOrWhiteSpace(cryptoLine)) { return(false); } if (!cryptoLine.StartsWith(CRYPTO_ATTRIBUE_PREFIX)) { throw new FormatException( $"cryptoLine '{cryptoLine}' is not recognized as a valid SDP Security Description "); } string sCryptoValue = cryptoLine.Substring(cryptoLine.IndexOf(COLON) + 1); securityDescription = new SDPSecurityDescription(); string[] sCryptoParts = sCryptoValue.Split(securityDescription.WHITE_SPACES, StringSplitOptions.RemoveEmptyEntries); if (sCryptoValue.Length < 2) { throw new FormatException( $"cryptoLine '{cryptoLine}' is not recognized as a valid SDP Security Description "); } try { securityDescription.Tag = uint.Parse(sCryptoParts[0]); securityDescription.CryptoSuite = (from e in Enum.GetNames(typeof(CryptoSuites)) where e.CompareTo(sCryptoParts[1]) == 0 select(CryptoSuites) Enum.Parse(typeof(CryptoSuites), e)).FirstOrDefault(); if (securityDescription.CryptoSuite == CryptoSuites.unknown) { //this may not be a reason to return FALSE //there might be a new crypto key used } string[] sKeyParams = sCryptoParts[2].Split(SEMI_COLON); if (sKeyParams.Length < 1) { securityDescription = null; return(false); } foreach (string kp in sKeyParams) { KeyParameter keyParam = KeyParameter.Parse(kp, securityDescription.CryptoSuite); securityDescription.KeyParams.Add(keyParam); } if (sCryptoParts.Length > 3) { securityDescription.SessionParam = SessionParameter.Parse(sCryptoParts[3], securityDescription.CryptoSuite); } return(true); } catch { //catch all errors and throw own FormatException } return(false); }