TransportSecurityInfoUtils.cpp (1806B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #include "TransportSecurityInfoUtils.h" 6 7 #include "ipc/IPCMessageUtils.h" 8 #include "mozilla/psm/TransportSecurityInfo.h" 9 #include "nsNSSCertificate.h" 10 11 namespace IPC { 12 13 void ParamTraits<nsITransportSecurityInfo*>::Write( 14 MessageWriter* aWriter, nsITransportSecurityInfo* aParam) { 15 bool nonNull = !!aParam; 16 WriteParam(aWriter, nonNull); 17 if (!nonNull) { 18 return; 19 } 20 21 aParam->SerializeToIPC(aWriter); 22 } 23 24 bool ParamTraits<nsITransportSecurityInfo*>::Read( 25 MessageReader* aReader, RefPtr<nsITransportSecurityInfo>* aResult) { 26 *aResult = nullptr; 27 28 bool nonNull = false; 29 if (!ReadParam(aReader, &nonNull)) { 30 return false; 31 } 32 33 if (!nonNull) { 34 return true; 35 } 36 37 if (!mozilla::psm::TransportSecurityInfo::DeserializeFromIPC(aReader, 38 aResult)) { 39 return false; 40 } 41 42 return true; 43 } 44 45 void ParamTraits<nsIX509Cert*>::Write(MessageWriter* aWriter, 46 nsIX509Cert* aParam) { 47 bool nonNull = !!aParam; 48 WriteParam(aWriter, nonNull); 49 if (!nonNull) { 50 return; 51 } 52 53 aParam->SerializeToIPC(aWriter); 54 } 55 56 bool ParamTraits<nsIX509Cert*>::Read(MessageReader* aReader, 57 RefPtr<nsIX509Cert>* aResult) { 58 *aResult = nullptr; 59 60 bool nonNull = false; 61 if (!ReadParam(aReader, &nonNull)) { 62 return false; 63 } 64 65 if (!nonNull) { 66 return true; 67 } 68 69 RefPtr<nsIX509Cert> cert = new nsNSSCertificate(); 70 if (!cert->DeserializeFromIPC(aReader)) { 71 return false; 72 } 73 74 *aResult = std::move(cert); 75 return true; 76 } 77 78 } // namespace IPC