AEGetQuoteResponse.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Copyright (C) 2011-2016 Intel Corporation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Intel Corporation nor the names of its
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. */
  31. #include <ISerializer.h>
  32. #include <AEGetQuoteResponse.h>
  33. #include <stdlib.h>
  34. #include <string.h>
  35. AEGetQuoteResponse::AEGetQuoteResponse() :
  36. mQuoteLength(0),
  37. mQuote(NULL),
  38. mQEReportLength(0),
  39. mQEReport(NULL)
  40. {
  41. }
  42. AEGetQuoteResponse::AEGetQuoteResponse(int errorCode, uint32_t quoteLength, const uint8_t* quote,
  43. uint32_t qeReportLength, const uint8_t* qeReport) :
  44. mQuoteLength(0),
  45. mQuote(NULL),
  46. mQEReportLength(0),
  47. mQEReport(NULL)
  48. {
  49. CopyFields(errorCode, quoteLength, quote,qeReportLength, qeReport);
  50. }
  51. //copy constructor
  52. AEGetQuoteResponse::AEGetQuoteResponse(const AEGetQuoteResponse& other) :
  53. mQuoteLength(0),
  54. mQuote(NULL),
  55. mQEReportLength(0),
  56. mQEReport(NULL)
  57. {
  58. CopyFields(other.mErrorCode, other.mQuoteLength, other.mQuote, other.mQEReportLength, other.mQEReport);
  59. }
  60. AEGetQuoteResponse::~AEGetQuoteResponse()
  61. {
  62. ReleaseMemory();
  63. }
  64. void AEGetQuoteResponse::ReleaseMemory()
  65. {
  66. if (mQuote != NULL)
  67. delete [] mQuote;
  68. if (mQEReport != NULL)
  69. delete [] mQEReport;
  70. mQuote = NULL;
  71. mQEReport = NULL;
  72. mQuoteLength = 0;
  73. mQEReportLength = 0;
  74. mErrorCode = SGX_ERROR_UNEXPECTED;
  75. }
  76. void AEGetQuoteResponse::CopyFields(int errorCode, uint32_t quoteLength,const uint8_t* quote,
  77. uint32_t qeReportLength, const uint8_t* qeReport)
  78. {
  79. uint32_t totalSize = qeReportLength + quoteLength;
  80. if(quoteLength <= MAX_MEMORY_ALLOCATION && qeReportLength <= MAX_MEMORY_ALLOCATION
  81. && totalSize <= MAX_MEMORY_ALLOCATION )
  82. {
  83. mValidSizeCheck = true;
  84. }
  85. else
  86. {
  87. mValidSizeCheck = false;
  88. return;
  89. }
  90. mErrorCode = errorCode;
  91. mQuoteLength = quoteLength;
  92. mQEReportLength = qeReportLength;
  93. if (quote != NULL && quoteLength > 0)
  94. {
  95. mQuote = new uint8_t[quoteLength];
  96. memcpy(mQuote, quote, quoteLength);
  97. }
  98. if (qeReport != NULL&& qeReportLength > 0)
  99. {
  100. mQEReport = new uint8_t[qeReportLength];
  101. memcpy(mQEReport, qeReport, qeReportLength);
  102. }
  103. }
  104. AEMessage* AEGetQuoteResponse::serialize(ISerializer* serializer)
  105. {
  106. return serializer->serialize(this);
  107. }
  108. bool AEGetQuoteResponse::inflateWithMessage(AEMessage* message, ISerializer* serializer)
  109. {
  110. return serializer->inflateResponse(message, this);
  111. }
  112. void AEGetQuoteResponse::inflateValues(int errorCode, uint32_t quoteLength, const uint8_t* quote,
  113. uint32_t qeReportLength, const uint8_t* qeReport)
  114. {
  115. ReleaseMemory();
  116. CopyFields(errorCode, quoteLength, quote, qeReportLength, qeReport);
  117. }
  118. bool AEGetQuoteResponse::operator==(const AEGetQuoteResponse& other) const
  119. {
  120. if (this == &other)
  121. return true;
  122. if (mErrorCode != other.mErrorCode ||
  123. mQuoteLength != other.mQuoteLength ||
  124. mQEReportLength != other.mQEReportLength)
  125. return false;
  126. if (mQuote != NULL && other.mQuote != NULL)
  127. if (memcmp(mQuote, other.mQuote, other.mQuoteLength) != 0)
  128. return false;
  129. if (mQEReport != NULL && other.mQEReport != NULL)
  130. if (memcmp(mQEReport, other.mQEReport, other.mQEReportLength) != 0)
  131. return false;
  132. return true;
  133. }
  134. AEGetQuoteResponse& AEGetQuoteResponse::operator=(const AEGetQuoteResponse& other)
  135. {
  136. if (this == &other)
  137. return *this;
  138. inflateValues(other.mErrorCode, other.mQuoteLength, other.mQuote, other.mQEReportLength, other.mQEReport);
  139. return *this;
  140. }
  141. bool AEGetQuoteResponse::check()
  142. {
  143. if (mValidSizeCheck == false)
  144. return false;
  145. return true;
  146. }
  147. void AEGetQuoteResponse::visit(IAEResponseVisitor& visitor)
  148. {
  149. visitor.visitGetQuoteResponse(*this);
  150. }