From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- dom/media/webrtc/PeerIdentity.h | 70 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 dom/media/webrtc/PeerIdentity.h (limited to 'dom/media/webrtc/PeerIdentity.h') diff --git a/dom/media/webrtc/PeerIdentity.h b/dom/media/webrtc/PeerIdentity.h new file mode 100644 index 0000000000..64364d3359 --- /dev/null +++ b/dom/media/webrtc/PeerIdentity.h @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * vim: sw=2 ts=2 sts=2 expandtab + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef PeerIdentity_h +#define PeerIdentity_h + +#include "nsISupportsImpl.h" +#include "nsString.h" + +template +class nsCOMPtr; +class nsIIDNService; + +namespace mozilla { + +/** + * This class implements the identifier used in WebRTC identity. Peers are + * identified using a string in the form [@], for instance, + * "user@example.com'. The (optional) user portion is a site-controlled string + * containing any character other than '@'. The domain portion is a valid IDN + * domain name and is compared accordingly. + * + * See: + * http://tools.ietf.org/html/draft-ietf-rtcweb-security-arch-09#section-5.6.5.3.3.1 + */ +class PeerIdentity final { + public: + NS_INLINE_DECL_REFCOUNTING(PeerIdentity) + + explicit PeerIdentity(const nsAString& aPeerIdentity) + : mPeerIdentity(aPeerIdentity) {} + + bool Equals(const PeerIdentity& aOther) const; + bool Equals(const nsAString& aOtherString) const; + const nsString& ToString() const { return mPeerIdentity; } + + private: + ~PeerIdentity() = default; + static void GetUser(const nsAString& aPeerIdentity, nsAString& aUser); + static void GetHost(const nsAString& aPeerIdentity, nsAString& aHost); + + static void GetNormalizedHost(const nsCOMPtr& aIdnService, + const nsAString& aHost, + nsACString& aNormalizedHost); + + nsString mPeerIdentity; +}; + +inline bool operator==(const PeerIdentity& aOne, const PeerIdentity& aTwo) { + return aOne.Equals(aTwo); +} + +inline bool operator==(const PeerIdentity& aOne, const nsAString& aString) { + return aOne.Equals(aString); +} + +inline bool operator!=(const PeerIdentity& aOne, const PeerIdentity& aTwo) { + return !aOne.Equals(aTwo); +} + +inline bool operator!=(const PeerIdentity& aOne, const nsAString& aString) { + return !aOne.Equals(aString); +} + +} /* namespace mozilla */ + +#endif /* PeerIdentity_h */ -- cgit v1.2.3