/*############################################################################
  # Copyright 2016 Intel Corporation
  #
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  #     http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  ############################################################################*/
/// 1.1 issuer material file parsing unit tests.
/*!
 * \file
 */
#include <cstdint>
#include <vector>

#include "gtest/gtest.h"
extern "C" {
#include "epid/common/1.1/file_parser.h"
}

namespace {

/// Test fixture class for Epid11FileParser
class Epid11FileParser : public ::testing::Test {
 public:
  /// Cert used to sign legitimate test data
  static const EpidCaCertificate kCert;

  /// A file with Epid11GroupPublicKey signed with kCert
  static const std::vector<uint8_t> kGroupPublicKeyFile;
  /// A file with two Epid11GroupPublicKey signed with kCert
  static const std::vector<uint8_t> kGroupMultiPublicKeyFile;
  /// Expected Epid11GroupPublicKey
  static const std::vector<uint8_t> kGroupPublicKey;

  /// A file with empty privrl signed with kCert
  static const std::vector<uint8_t> kEmptyPrivRlFile;
  /// Expected empty privrl
  static const std::vector<uint8_t> kEmptyPrivRl;
  /// A file with short privrl signed with kCert
  static const std::vector<uint8_t> kShortPrivRlFile;
  /// Expected short privrl
  static const std::vector<uint8_t> kShortPrivRl;

  /// A file with empty SigRl signed with kCert
  static const std::vector<uint8_t> kEmptySigRlFile;
  /// Expected empty SigRl
  static const std::vector<uint8_t> kEmptySigRl;
  /// A file with short SigRl signed with kCert
  static const std::vector<uint8_t> kShortSigRlFile;
  /// Expected short SigRl
  static const std::vector<uint8_t> kShortSigRl;

  /// A file with empty GroupRl signed with kCert
  static const std::vector<uint8_t> kEmptyGroupRlFile;
  /// Expected empty GroupRl
  static const std::vector<uint8_t> kEmptyGroupRl;
  /// A file with short GroupRl signed with kCert
  static const std::vector<uint8_t> kShortGroupRlFile;
  /// Expected short GroupRl
  static const std::vector<uint8_t> kShortGroupRl;
};
const EpidCaCertificate Epid11FileParser::kCert = {
    // EpidFileHeader::epid_version
    0x02, 0x00,
    // EpidFileHeader::file_type
    0x00, 0x11,
    // pubkey
    0x24, 0x42, 0xa5, 0xcc, 0x0e, 0xcd, 0x01, 0x5f, 0xa3, 0xca, 0x31, 0xdc,
    0x8e, 0x2b, 0xbc, 0x70, 0xbf, 0x42, 0xd6, 0x0c, 0xbc, 0xa2, 0x00, 0x85,
    0xe0, 0x82, 0x2c, 0xb0, 0x42, 0x35, 0xe9, 0x70, 0x6f, 0xc9, 0x8b, 0xd7,
    0xe5, 0x02, 0x11, 0xa4, 0xa2, 0x71, 0x02, 0xfa, 0x35, 0x49, 0xdf, 0x79,
    0xeb, 0xcb, 0x4b, 0xf2, 0x46, 0xb8, 0x09, 0x45, 0xcd, 0xdf, 0xe7, 0xd5,
    0x09, 0xbb, 0xfd, 0x7d,
    // prime
    0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
    // a
    0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
    // b
    0x5a, 0xc6, 0x35, 0xd8, 0xaa, 0x3a, 0x93, 0xe7, 0xb3, 0xeb, 0xbd, 0x55,
    0x76, 0x98, 0x86, 0xbc, 0x65, 0x1d, 0x06, 0xb0, 0xcc, 0x53, 0xb0, 0xf6,
    0x3b, 0xce, 0x3c, 0x3e, 0x27, 0xd2, 0x60, 0x4b,
    // x
    0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc, 0xe6, 0xe5,
    0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81, 0x2d, 0xeb, 0x33, 0xa0,
    0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
    // y
    0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb, 0x4a,
    0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31, 0x5e, 0xce,
    0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5,
    // r
    0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
    0xff, 0xff, 0xff, 0xff, 0xbc, 0xe6, 0xfa, 0xad, 0xa7, 0x17, 0x9e, 0x84,
    0xf3, 0xb9, 0xca, 0xc2, 0xfc, 0x63, 0x25, 0x51,
    // signature::x
    0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a,
    0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06,
    0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7,
    // signature::y
    0x94, 0x03, 0x1d, 0x90, 0x6b, 0x6f, 0xcd, 0x99, 0xef, 0x2c, 0xdb, 0x8b,
    0xa9, 0x8a, 0xef, 0x7e, 0xf0, 0x77, 0xba, 0xb5, 0x11, 0x43, 0x0d, 0x28,
    0x1c, 0x01, 0x5b, 0xc9, 0x08, 0xce, 0x3e, 0x68};

const std::vector<uint8_t> Epid11FileParser::kGroupPublicKeyFile = {
    // Epid Version
    0x01, 0x00,
    // Epid type
    0x00, 0x0c,
    // GID
    0x00, 0x00, 0x00, 0x7b,
    // h1
    0x08, 0x4a, 0x9d, 0x2e, 0xf9, 0x4f, 0x78, 0x02, 0xd7, 0x89, 0x75, 0xb4,
    0xe7, 0x25, 0x26, 0x9f, 0x00, 0x57, 0xad, 0x33, 0x30, 0xea, 0xa9, 0x6c,
    0x00, 0x9e, 0x8b, 0xc8, 0x13, 0x23, 0xcb, 0x06, 0x04, 0xbe, 0x42, 0x74,
    0x11, 0x07, 0xb1, 0x06, 0xd7, 0xef, 0x5f, 0x66, 0x87, 0xd9, 0xfa, 0xdd,
    0x53, 0xae, 0xd7, 0xf4, 0x54, 0xf8, 0xd0, 0x21, 0x75, 0xe0, 0x07, 0x44,
    0xc9, 0xc3, 0x4e, 0xf7,
    // h2
    0x06, 0xd8, 0xa9, 0x90, 0x02, 0x8f, 0xca, 0xa5, 0x73, 0x36, 0x24, 0x03,
    0xc9, 0xa8, 0x7e, 0x9d, 0x64, 0x12, 0xac, 0xa7, 0xbd, 0x17, 0x7f, 0x7c,
    0x96, 0x8d, 0x2e, 0x13, 0xd9, 0xb2, 0x69, 0x47, 0x09, 0xdb, 0xe3, 0xbf,
    0xbc, 0xa1, 0x34, 0x0f, 0xc6, 0xe2, 0x00, 0x3d, 0x98, 0xa3, 0x7d, 0xab,
    0xd4, 0x0e, 0xec, 0xde, 0x4f, 0x97, 0xa9, 0xbb, 0xdd, 0x60, 0x94, 0x24,
    0x7b, 0xb3, 0xf5, 0x94,
    // w
    0x02, 0x43, 0x78, 0x9f, 0x54, 0xc1, 0x21, 0x3a, 0x2b, 0x4d, 0x12, 0x65,
    0x2f, 0x51, 0x94, 0xc6, 0x34, 0x24, 0xd9, 0x7b, 0x06, 0x3a, 0xc4, 0xf5,
    0x56, 0xeb, 0x32, 0xe3, 0xee, 0x7b, 0xad, 0x6b, 0x04, 0x90, 0x86, 0x31,
    0x18, 0x2a, 0xa4, 0xcf, 0xa3, 0x90, 0xa5, 0x80, 0x7b, 0xae, 0x3b, 0xb1,
    0x77, 0x03, 0xe7, 0x7e, 0xf2, 0xfc, 0x6d, 0x3a, 0xab, 0x8f, 0xbf, 0x95,
    0x40, 0xed, 0x08, 0x03, 0x01, 0x05, 0x86, 0xf5, 0x42, 0xea, 0x4d, 0xf7,
    0x4f, 0xef, 0x46, 0xdf, 0x8f, 0xe8, 0x2d, 0xbb, 0x5d, 0x0d, 0x2f, 0x4f,
    0xf4, 0xd8, 0x31, 0xc6, 0x5a, 0x97, 0x98, 0x44, 0xcf, 0x42, 0x5a, 0xf3,
    0x03, 0x5f, 0xb6, 0x38, 0x45, 0x5a, 0x15, 0x1e, 0xb9, 0x54, 0xfa, 0x2c,
    0x3f, 0x68, 0x7b, 0x4e, 0x85, 0x35, 0xf3, 0x5b, 0xe5, 0xdc, 0x96, 0x2b,
    0x18, 0x84, 0x5e, 0x1e, 0x53, 0xdc, 0x22, 0x23, 0x06, 0x08, 0x91, 0x5a,
    0x2d, 0x27, 0xe2, 0x12, 0x69, 0xfa, 0xab, 0x19, 0x7c, 0x47, 0x6b, 0xec,
    0xde, 0xc6, 0x25, 0xd4, 0x43, 0xb4, 0x65, 0x23, 0x61, 0x0f, 0x1f, 0x2d,
    0xfd, 0xb1, 0x18, 0xb0, 0x04, 0x8e, 0x1a, 0xc5, 0x95, 0x9a, 0x0e, 0x37,
    0x7c, 0x5e, 0x95, 0x38, 0xc2, 0xcf, 0xfa, 0x1f, 0xe3, 0x3a, 0x2b, 0x85,
    0xa5, 0xfd, 0x6b, 0xc4, 0x1d, 0xfb, 0x47, 0x27, 0xaf, 0xc1, 0x94, 0xcd,
    // Signature
    0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a,
    0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06,
    0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0xf0, 0x6e, 0x43, 0x67,
    0x68, 0x6f, 0x9e, 0x3b, 0xcf, 0xfd, 0x98, 0xcc, 0xae, 0x92, 0xcc, 0x94,
    0x23, 0xb6, 0xbd, 0x57, 0xac, 0x06, 0x3c, 0xa1, 0xe5, 0x3e, 0xe9, 0xf5,
    0x0e, 0x55, 0xb4, 0xe5};
const std::vector<uint8_t> Epid11FileParser::kGroupPublicKey = {
    // GID
    0x00, 0x00, 0x00, 0x7b,
    // h1
    0x08, 0x4a, 0x9d, 0x2e, 0xf9, 0x4f, 0x78, 0x02, 0xd7, 0x89, 0x75, 0xb4,
    0xe7, 0x25, 0x26, 0x9f, 0x00, 0x57, 0xad, 0x33, 0x30, 0xea, 0xa9, 0x6c,
    0x00, 0x9e, 0x8b, 0xc8, 0x13, 0x23, 0xcb, 0x06, 0x04, 0xbe, 0x42, 0x74,
    0x11, 0x07, 0xb1, 0x06, 0xd7, 0xef, 0x5f, 0x66, 0x87, 0xd9, 0xfa, 0xdd,
    0x53, 0xae, 0xd7, 0xf4, 0x54, 0xf8, 0xd0, 0x21, 0x75, 0xe0, 0x07, 0x44,
    0xc9, 0xc3, 0x4e, 0xf7,
    // h2
    0x06, 0xd8, 0xa9, 0x90, 0x02, 0x8f, 0xca, 0xa5, 0x73, 0x36, 0x24, 0x03,
    0xc9, 0xa8, 0x7e, 0x9d, 0x64, 0x12, 0xac, 0xa7, 0xbd, 0x17, 0x7f, 0x7c,
    0x96, 0x8d, 0x2e, 0x13, 0xd9, 0xb2, 0x69, 0x47, 0x09, 0xdb, 0xe3, 0xbf,
    0xbc, 0xa1, 0x34, 0x0f, 0xc6, 0xe2, 0x00, 0x3d, 0x98, 0xa3, 0x7d, 0xab,
    0xd4, 0x0e, 0xec, 0xde, 0x4f, 0x97, 0xa9, 0xbb, 0xdd, 0x60, 0x94, 0x24,
    0x7b, 0xb3, 0xf5, 0x94,
    // w
    0x02, 0x43, 0x78, 0x9f, 0x54, 0xc1, 0x21, 0x3a, 0x2b, 0x4d, 0x12, 0x65,
    0x2f, 0x51, 0x94, 0xc6, 0x34, 0x24, 0xd9, 0x7b, 0x06, 0x3a, 0xc4, 0xf5,
    0x56, 0xeb, 0x32, 0xe3, 0xee, 0x7b, 0xad, 0x6b, 0x04, 0x90, 0x86, 0x31,
    0x18, 0x2a, 0xa4, 0xcf, 0xa3, 0x90, 0xa5, 0x80, 0x7b, 0xae, 0x3b, 0xb1,
    0x77, 0x03, 0xe7, 0x7e, 0xf2, 0xfc, 0x6d, 0x3a, 0xab, 0x8f, 0xbf, 0x95,
    0x40, 0xed, 0x08, 0x03, 0x01, 0x05, 0x86, 0xf5, 0x42, 0xea, 0x4d, 0xf7,
    0x4f, 0xef, 0x46, 0xdf, 0x8f, 0xe8, 0x2d, 0xbb, 0x5d, 0x0d, 0x2f, 0x4f,
    0xf4, 0xd8, 0x31, 0xc6, 0x5a, 0x97, 0x98, 0x44, 0xcf, 0x42, 0x5a, 0xf3,
    0x03, 0x5f, 0xb6, 0x38, 0x45, 0x5a, 0x15, 0x1e, 0xb9, 0x54, 0xfa, 0x2c,
    0x3f, 0x68, 0x7b, 0x4e, 0x85, 0x35, 0xf3, 0x5b, 0xe5, 0xdc, 0x96, 0x2b,
    0x18, 0x84, 0x5e, 0x1e, 0x53, 0xdc, 0x22, 0x23, 0x06, 0x08, 0x91, 0x5a,
    0x2d, 0x27, 0xe2, 0x12, 0x69, 0xfa, 0xab, 0x19, 0x7c, 0x47, 0x6b, 0xec,
    0xde, 0xc6, 0x25, 0xd4, 0x43, 0xb4, 0x65, 0x23, 0x61, 0x0f, 0x1f, 0x2d,
    0xfd, 0xb1, 0x18, 0xb0, 0x04, 0x8e, 0x1a, 0xc5, 0x95, 0x9a, 0x0e, 0x37,
    0x7c, 0x5e, 0x95, 0x38, 0xc2, 0xcf, 0xfa, 0x1f, 0xe3, 0x3a, 0x2b, 0x85,
    0xa5, 0xfd, 0x6b, 0xc4, 0x1d, 0xfb, 0x47, 0x27, 0xaf, 0xc1, 0x94, 0xcd};

const std::vector<uint8_t> Epid11FileParser::kGroupMultiPublicKeyFile = {
    // Epid Version
    0x01, 0x00,
    // Epid type
    0x00, 0x0c,
    // GID
    0x00, 0x00, 0x00, 0x7b,
    // h1
    0x08, 0x4a, 0x9d, 0x2e, 0xf9, 0x4f, 0x78, 0x02, 0xd7, 0x89, 0x75, 0xb4,
    0xe7, 0x25, 0x26, 0x9f, 0x00, 0x57, 0xad, 0x33, 0x30, 0xea, 0xa9, 0x6c,
    0x00, 0x9e, 0x8b, 0xc8, 0x13, 0x23, 0xcb, 0x06, 0x04, 0xbe, 0x42, 0x74,
    0x11, 0x07, 0xb1, 0x06, 0xd7, 0xef, 0x5f, 0x66, 0x87, 0xd9, 0xfa, 0xdd,
    0x53, 0xae, 0xd7, 0xf4, 0x54, 0xf8, 0xd0, 0x21, 0x75, 0xe0, 0x07, 0x44,
    0xc9, 0xc3, 0x4e, 0xf7,
    // h2
    0x06, 0xd8, 0xa9, 0x90, 0x02, 0x8f, 0xca, 0xa5, 0x73, 0x36, 0x24, 0x03,
    0xc9, 0xa8, 0x7e, 0x9d, 0x64, 0x12, 0xac, 0xa7, 0xbd, 0x17, 0x7f, 0x7c,
    0x96, 0x8d, 0x2e, 0x13, 0xd9, 0xb2, 0x69, 0x47, 0x09, 0xdb, 0xe3, 0xbf,
    0xbc, 0xa1, 0x34, 0x0f, 0xc6, 0xe2, 0x00, 0x3d, 0x98, 0xa3, 0x7d, 0xab,
    0xd4, 0x0e, 0xec, 0xde, 0x4f, 0x97, 0xa9, 0xbb, 0xdd, 0x60, 0x94, 0x24,
    0x7b, 0xb3, 0xf5, 0x94,
    // w
    0x02, 0x43, 0x78, 0x9f, 0x54, 0xc1, 0x21, 0x3a, 0x2b, 0x4d, 0x12, 0x65,
    0x2f, 0x51, 0x94, 0xc6, 0x34, 0x24, 0xd9, 0x7b, 0x06, 0x3a, 0xc4, 0xf5,
    0x56, 0xeb, 0x32, 0xe3, 0xee, 0x7b, 0xad, 0x6b, 0x04, 0x90, 0x86, 0x31,
    0x18, 0x2a, 0xa4, 0xcf, 0xa3, 0x90, 0xa5, 0x80, 0x7b, 0xae, 0x3b, 0xb1,
    0x77, 0x03, 0xe7, 0x7e, 0xf2, 0xfc, 0x6d, 0x3a, 0xab, 0x8f, 0xbf, 0x95,
    0x40, 0xed, 0x08, 0x03, 0x01, 0x05, 0x86, 0xf5, 0x42, 0xea, 0x4d, 0xf7,
    0x4f, 0xef, 0x46, 0xdf, 0x8f, 0xe8, 0x2d, 0xbb, 0x5d, 0x0d, 0x2f, 0x4f,
    0xf4, 0xd8, 0x31, 0xc6, 0x5a, 0x97, 0x98, 0x44, 0xcf, 0x42, 0x5a, 0xf3,
    0x03, 0x5f, 0xb6, 0x38, 0x45, 0x5a, 0x15, 0x1e, 0xb9, 0x54, 0xfa, 0x2c,
    0x3f, 0x68, 0x7b, 0x4e, 0x85, 0x35, 0xf3, 0x5b, 0xe5, 0xdc, 0x96, 0x2b,
    0x18, 0x84, 0x5e, 0x1e, 0x53, 0xdc, 0x22, 0x23, 0x06, 0x08, 0x91, 0x5a,
    0x2d, 0x27, 0xe2, 0x12, 0x69, 0xfa, 0xab, 0x19, 0x7c, 0x47, 0x6b, 0xec,
    0xde, 0xc6, 0x25, 0xd4, 0x43, 0xb4, 0x65, 0x23, 0x61, 0x0f, 0x1f, 0x2d,
    0xfd, 0xb1, 0x18, 0xb0, 0x04, 0x8e, 0x1a, 0xc5, 0x95, 0x9a, 0x0e, 0x37,
    0x7c, 0x5e, 0x95, 0x38, 0xc2, 0xcf, 0xfa, 0x1f, 0xe3, 0x3a, 0x2b, 0x85,
    0xa5, 0xfd, 0x6b, 0xc4, 0x1d, 0xfb, 0x47, 0x27, 0xaf, 0xc1, 0x94, 0xcd,
    // Signature
    0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a,
    0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06,
    0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0xf0, 0x6e, 0x43, 0x67,
    0x68, 0x6f, 0x9e, 0x3b, 0xcf, 0xfd, 0x98, 0xcc, 0xae, 0x92, 0xcc, 0x94,
    0x23, 0xb6, 0xbd, 0x57, 0xac, 0x06, 0x3c, 0xa1, 0xe5, 0x3e, 0xe9, 0xf5,
    0x0e, 0x55, 0xb4, 0xe5,
    // Epid Version
    0x01, 0x00,
    // Epid type
    0x00, 0x0c,
    // GID
    0x00, 0x00, 0x04, 0xd2,
    // h1
    0x00, 0x6c, 0x38, 0x98, 0x41, 0x97, 0xf6, 0xf1, 0xb0, 0x41, 0x57, 0xd4,
    0xf9, 0xce, 0xcc, 0x22, 0xce, 0x4f, 0xc8, 0x47, 0xaf, 0x2a, 0x6c, 0xa3,
    0x02, 0xf2, 0x74, 0x80, 0xc9, 0x5c, 0x1c, 0xf7, 0x06, 0xed, 0xce, 0xc0,
    0x0b, 0x29, 0x73, 0x1c, 0x09, 0x84, 0x4c, 0xcc, 0xff, 0x82, 0x9d, 0x29,
    0xe7, 0x88, 0x57, 0xfd, 0xd2, 0x55, 0x41, 0x0f, 0x5e, 0x6e, 0xf5, 0xc4,
    0x77, 0xa2, 0x5d, 0xaf,
    // h2
    0x00, 0x50, 0x70, 0xe5, 0x66, 0x92, 0x77, 0x33, 0x82, 0xda, 0xc9, 0x27,
    0x7c, 0x16, 0xf8, 0xf2, 0x69, 0x48, 0x2f, 0xf0, 0xdd, 0x8d, 0x9e, 0x27,
    0x41, 0xaf, 0xcc, 0xb9, 0x04, 0xf4, 0x77, 0x8c, 0x06, 0x36, 0xee, 0xbd,
    0x53, 0x0e, 0x20, 0xd8, 0x9f, 0xd7, 0xb7, 0x41, 0xdd, 0xe0, 0xee, 0xc7,
    0xf8, 0xef, 0x91, 0x03, 0xe1, 0xfe, 0x6a, 0xe6, 0x3b, 0x91, 0xb7, 0xaa,
    0xc4, 0x64, 0x72, 0x37,
    // w
    0x06, 0xa3, 0x37, 0xa1, 0xfc, 0xe2, 0x3a, 0x99, 0x96, 0xb9, 0x8d, 0xad,
    0x07, 0xec, 0xfc, 0x62, 0x39, 0x5c, 0x0c, 0x89, 0xba, 0x06, 0x3a, 0x1c,
    0xea, 0x2d, 0xcc, 0xf2, 0x00, 0xaa, 0x08, 0x25, 0x06, 0x82, 0xa0, 0x68,
    0x71, 0x4f, 0x5d, 0xbd, 0xc3, 0x80, 0xe6, 0x98, 0xe9, 0x14, 0x10, 0xdc,
    0x9c, 0xa6, 0x4e, 0x75, 0x09, 0x0a, 0x45, 0x39, 0x2b, 0xcc, 0x6e, 0x6f,
    0x66, 0xad, 0x1a, 0x63, 0x05, 0x9c, 0x6a, 0xeb, 0x7f, 0xd3, 0x16, 0x46,
    0x37, 0xc8, 0x5f, 0x1a, 0x34, 0x46, 0x35, 0x92, 0x10, 0x7b, 0x7b, 0xe3,
    0x9c, 0x65, 0x59, 0x2d, 0xa8, 0x8a, 0x4b, 0xfb, 0x81, 0x97, 0xf6, 0x25,
    0x09, 0xf3, 0x6d, 0xcc, 0x50, 0x63, 0xe0, 0x9d, 0x69, 0x02, 0x0c, 0x52,
    0x75, 0x95, 0x30, 0x38, 0x69, 0x1e, 0x8e, 0x6b, 0x52, 0xbf, 0x97, 0x9f,
    0x20, 0x02, 0xec, 0xb3, 0x6b, 0x2b, 0xdd, 0xf3, 0x01, 0x11, 0xbb, 0xbe,
    0x3b, 0xc9, 0xa0, 0xc3, 0x44, 0xfe, 0x49, 0x53, 0x89, 0x2d, 0x27, 0x40,
    0x86, 0x87, 0xea, 0xce, 0x5f, 0x9a, 0xee, 0xc2, 0x15, 0x62, 0xc1, 0x87,
    0x0f, 0x3a, 0x78, 0x03, 0x03, 0xd2, 0x8c, 0x24, 0x5a, 0x90, 0xa7, 0xc5,
    0x35, 0x4f, 0xab, 0xcd, 0x40, 0xe8, 0x7c, 0xf0, 0xab, 0x96, 0x59, 0x3a,
    0x96, 0xe4, 0x4a, 0x73, 0x67, 0x51, 0x1f, 0xad, 0x06, 0x94, 0x40, 0xcf,
    // Signature
    0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a,
    0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06,
    0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x4b, 0xba, 0x99, 0x05,
    0x14, 0x98, 0x2c, 0x10, 0x5d, 0x25, 0x84, 0x93, 0x92, 0x0c, 0x7c, 0x44,
    0x39, 0xb8, 0xd9, 0x65, 0x8a, 0x27, 0x20, 0x31, 0xb8, 0xc8, 0x47, 0xe2,
    0xfb, 0x79, 0xa0, 0xa5};

const std::vector<uint8_t> Epid11FileParser::kEmptyPrivRlFile = {
    // Epid Version
    0x01, 0x00,
    // Epid type
    0x00, 0x0d,
    // GID
    0x00, 0x00, 0x00, 0x7b,
    // RL Ver
    0x00, 0x00, 0x00, 0x00,
    // n1
    0x00, 0x00, 0x00, 0x00,
    // sig
    0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a,
    0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06,
    0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x29, 0xa4, 0x10, 0x8f,
    0x7d, 0xb4, 0xff, 0xae, 0x6a, 0xce, 0x8d, 0xcd, 0xc6, 0x84, 0x63, 0x9f,
    0x89, 0x3d, 0x23, 0x42, 0xf5, 0x37, 0xba, 0xb9, 0x4a, 0xbb, 0x6e, 0xf2,
    0xb2, 0x74, 0x8c, 0xcc,
};
const std::vector<uint8_t> Epid11FileParser::kEmptyPrivRl = {
    // GID
    0x00, 0x00, 0x00, 0x7b,
    // RL Ver
    0x00, 0x00, 0x00, 0x00,
    // n1
    0x00, 0x00, 0x00, 0x00};

const std::vector<uint8_t> Epid11FileParser::kShortPrivRlFile = {
    // Epid Version
    0x01, 0x00,
    // Epid type
    0x00, 0x0d,
    // GID
    0x00, 0x00, 0x00, 0x7b,
    // RL Ver
    0x00, 0x00, 0x00, 0x03,
    // n1
    0x00, 0x00, 0x00, 0x01,
    // PrivRl
    0x00, 0x00, 0x56, 0x1e, 0xb1, 0x91, 0xb6, 0xdf, 0x40, 0xbc, 0xa2, 0xe3,
    0xe3, 0x92, 0x33, 0xd1, 0xd7, 0x5c, 0xcc, 0x4c, 0x3a, 0xe7, 0x91, 0x49,
    0x73, 0xe2, 0x03, 0xd4, 0x5e, 0x4f, 0x87, 0xad,
    // Sig
    0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a,
    0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06,
    0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x60, 0xf3, 0xfa, 0xe8,
    0x34, 0x9f, 0x50, 0xac, 0x1b, 0x75, 0xf4, 0x62, 0x41, 0xc4, 0xb7, 0x11,
    0x64, 0xef, 0xe1, 0xd4, 0x3c, 0xee, 0xee, 0x86, 0x4c, 0xbb, 0x9a, 0x40,
    0x77, 0x0b, 0xb2, 0xec,
};
const std::vector<uint8_t> Epid11FileParser::kShortPrivRl = {
    // GID
    0x00, 0x00, 0x00, 0x7b,
    // RL Ver
    0x00, 0x00, 0x00, 0x03,
    // n1
    0x00, 0x00, 0x00, 0x01,
    // PrivRl
    0x00, 0x00, 0x56, 0x1e, 0xb1, 0x91, 0xb6, 0xdf, 0x40, 0xbc, 0xa2, 0xe3,
    0xe3, 0x92, 0x33, 0xd1, 0xd7, 0x5c, 0xcc, 0x4c, 0x3a, 0xe7, 0x91, 0x49,
    0x73, 0xe2, 0x03, 0xd4, 0x5e, 0x4f, 0x87, 0xad,
};

const std::vector<uint8_t> Epid11FileParser::kEmptySigRlFile = {
    // Epid Version
    0x01, 0x00,
    // Epid type
    0x00, 0x0e,
    // GID
    0x00, 0x00, 0x00, 0x7b,
    // RL Ver
    0x00, 0x00, 0x00, 0x00,
    // n2
    0x00, 0x00, 0x00, 0x00,
    // Signature
    0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a,
    0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06,
    0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x94, 0x29, 0xf2, 0x7e,
    0x16, 0x19, 0x48, 0xa0, 0xed, 0xb7, 0x61, 0x5e, 0x63, 0x54, 0x87, 0xf4,
    0xbb, 0x7f, 0x42, 0x8d, 0x39, 0x63, 0x62, 0x06, 0x69, 0x7b, 0x9d, 0x0b,
    0x7e, 0xdf, 0xf2, 0x0d};
const std::vector<uint8_t> Epid11FileParser::kEmptySigRl = {
    // GID
    0x00, 0x00, 0x00, 0x7b,
    // RL Ver
    0x00, 0x00, 0x00, 0x00,
    // n2
    0x00, 0x00, 0x00, 0x00};

const std::vector<uint8_t> Epid11FileParser::kShortSigRlFile = {
    // Epid Version
    0x01, 0x00,
    // Epid type
    0x00, 0x0e,
    // GID
    0x00, 0x00, 0x00, 0x7b,
    // RL Ver
    0x00, 0x00, 0x00, 0x03,
    // n2
    0x00, 0x00, 0x00, 0x03,
    // bks
    0x09, 0x0d, 0x6f, 0x82, 0x77, 0x88, 0x49, 0x53, 0xba, 0x1e, 0x1b, 0x0e,
    0x5e, 0xae, 0xc0, 0x27, 0xad, 0xe3, 0xb1, 0x09, 0x4f, 0xcd, 0xb6, 0xe6,
    0x6f, 0x7f, 0xa3, 0x1a, 0x1e, 0xfb, 0x52, 0x72, 0xfa, 0x85, 0x0f, 0x5c,
    0x97, 0x61, 0xbf, 0x46, 0x7e, 0xec, 0xd6, 0x64, 0xda, 0xa9, 0x8e, 0xf5,
    0xd3, 0xdf, 0xfa, 0x13, 0x5a, 0xb2, 0x3e, 0xeb, 0x0a, 0x9d, 0x02, 0xc0,
    0x33, 0xec, 0x2a, 0x70, 0x6e, 0xdf, 0x9f, 0xe3, 0xe0, 0x8d, 0xe4, 0x0b,
    0xbb, 0x86, 0x12, 0xd7, 0xc5, 0xd8, 0x14, 0x5e, 0x67, 0xbd, 0x1d, 0xa5,
    0x0b, 0xdb, 0xf5, 0x87, 0x36, 0x6c, 0xda, 0x81, 0x2a, 0x8c, 0x2e, 0x78,
    0xef, 0x6c, 0x42, 0xb2, 0xcd, 0x40, 0xda, 0xd3, 0x22, 0xf4, 0xd9, 0x7e,
    0x34, 0x78, 0x49, 0x41, 0x0d, 0x1e, 0x64, 0xc1, 0x43, 0xa1, 0xb0, 0xe9,
    0x6c, 0x45, 0xe2, 0x2d, 0xc3, 0xeb, 0xc8, 0x14, 0x09, 0x0d, 0x6f, 0x82,
    0x77, 0x88, 0x49, 0x53, 0xba, 0x1e, 0x1b, 0x0e, 0x5e, 0xae, 0xc0, 0x27,
    0xad, 0xe3, 0xb1, 0x09, 0x4f, 0xcd, 0xb6, 0xe6, 0x6f, 0x7f, 0xa3, 0x1a,
    0x1e, 0xfb, 0x52, 0x72, 0xfa, 0x85, 0x0f, 0x5c, 0x97, 0x61, 0xbf, 0x46,
    0x7e, 0xec, 0xd6, 0x64, 0xda, 0xa9, 0x8e, 0xf5, 0xd3, 0xdf, 0xfa, 0x13,
    0x5a, 0xb2, 0x3e, 0xeb, 0x0a, 0x9d, 0x02, 0xc0, 0x33, 0xec, 0x2a, 0x70,
    0x80, 0x85, 0x35, 0x04, 0x7b, 0xfc, 0x0a, 0x6c, 0xb4, 0x10, 0x2d, 0x4a,
    0xbe, 0x35, 0x78, 0x41, 0x3a, 0xc6, 0x01, 0x3a, 0x59, 0x21, 0x17, 0x04,
    0x60, 0x6a, 0x51, 0x6c, 0x84, 0xde, 0xc3, 0x3b, 0x1e, 0x6a, 0xaf, 0x82,
    0x5d, 0x81, 0xe2, 0x44, 0x25, 0x98, 0x89, 0xdb, 0x82, 0x17, 0xe6, 0xb8,
    0x9f, 0xfd, 0x03, 0x86, 0x63, 0x8c, 0xe1, 0x93, 0x77, 0x61, 0x3c, 0xc2,
    0x75, 0x14, 0xa1, 0xc2, 0x09, 0x0d, 0x6f, 0x82, 0x77, 0x88, 0x49, 0x53,
    0xba, 0x1e, 0x1b, 0x0e, 0x5e, 0xae, 0xc0, 0x27, 0xad, 0xe3, 0xb1, 0x09,
    0x4f, 0xcd, 0xb6, 0xe6, 0x6f, 0x7f, 0xa3, 0x1a, 0x1e, 0xfb, 0x52, 0x72,
    0xfa, 0x85, 0x0f, 0x5c, 0x97, 0x61, 0xbf, 0x46, 0x7e, 0xec, 0xd6, 0x64,
    0xda, 0xa9, 0x8e, 0xf5, 0xd3, 0xdf, 0xfa, 0x13, 0x5a, 0xb2, 0x3e, 0xeb,
    0x0a, 0x9d, 0x02, 0xc0, 0x33, 0xec, 0x2a, 0x70, 0x95, 0x8b, 0x05, 0x1e,
    0x8b, 0xa5, 0x21, 0xdd, 0x63, 0xfd, 0x1a, 0x36, 0xb7, 0x42, 0x04, 0x92,
    0x10, 0xe6, 0x29, 0x22, 0xc8, 0x97, 0xb1, 0x28, 0x01, 0x45, 0x95, 0xf1,
    0x2a, 0xa0, 0x86, 0x41, 0xc4, 0x4c, 0xb6, 0x3b, 0x45, 0x23, 0x6e, 0x8d,
    0x6e, 0x07, 0xc7, 0x5b, 0xe5, 0x46, 0xca, 0xd0, 0x68, 0x99, 0xb6, 0x30,
    0x7b, 0x70, 0xb0, 0x92, 0x48, 0xc2, 0x89, 0xb6, 0x27, 0x3b, 0x95, 0x89,
    // Signature
    0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a,
    0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06,
    0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x1c, 0xab, 0x1f, 0xca,
    0x99, 0x74, 0x76, 0x02, 0x4c, 0xa6, 0xca, 0x13, 0xda, 0x9d, 0x74, 0xfa,
    0x56, 0x23, 0xf1, 0x86, 0xbe, 0xd4, 0xf2, 0x84, 0x7a, 0xdf, 0xd3, 0x62,
    0x4f, 0xc2, 0x0d, 0x84};
const std::vector<uint8_t> Epid11FileParser::kShortSigRl = {
    // GID
    0x00, 0x00, 0x00, 0x7b,
    // RL Ver
    0x00, 0x00, 0x00, 0x03,
    // n2
    0x00, 0x00, 0x00, 0x03,
    // B, K
    0x09, 0x0d, 0x6f, 0x82, 0x77, 0x88, 0x49, 0x53, 0xba, 0x1e, 0x1b, 0x0e,
    0x5e, 0xae, 0xc0, 0x27, 0xad, 0xe3, 0xb1, 0x09, 0x4f, 0xcd, 0xb6, 0xe6,
    0x6f, 0x7f, 0xa3, 0x1a, 0x1e, 0xfb, 0x52, 0x72, 0xfa, 0x85, 0x0f, 0x5c,
    0x97, 0x61, 0xbf, 0x46, 0x7e, 0xec, 0xd6, 0x64, 0xda, 0xa9, 0x8e, 0xf5,
    0xd3, 0xdf, 0xfa, 0x13, 0x5a, 0xb2, 0x3e, 0xeb, 0x0a, 0x9d, 0x02, 0xc0,
    0x33, 0xec, 0x2a, 0x70, 0x6e, 0xdf, 0x9f, 0xe3, 0xe0, 0x8d, 0xe4, 0x0b,
    0xbb, 0x86, 0x12, 0xd7, 0xc5, 0xd8, 0x14, 0x5e, 0x67, 0xbd, 0x1d, 0xa5,
    0x0b, 0xdb, 0xf5, 0x87, 0x36, 0x6c, 0xda, 0x81, 0x2a, 0x8c, 0x2e, 0x78,
    0xef, 0x6c, 0x42, 0xb2, 0xcd, 0x40, 0xda, 0xd3, 0x22, 0xf4, 0xd9, 0x7e,
    0x34, 0x78, 0x49, 0x41, 0x0d, 0x1e, 0x64, 0xc1, 0x43, 0xa1, 0xb0, 0xe9,
    0x6c, 0x45, 0xe2, 0x2d, 0xc3, 0xeb, 0xc8, 0x14,
    // B, K
    0x09, 0x0d, 0x6f, 0x82, 0x77, 0x88, 0x49, 0x53, 0xba, 0x1e, 0x1b, 0x0e,
    0x5e, 0xae, 0xc0, 0x27, 0xad, 0xe3, 0xb1, 0x09, 0x4f, 0xcd, 0xb6, 0xe6,
    0x6f, 0x7f, 0xa3, 0x1a, 0x1e, 0xfb, 0x52, 0x72, 0xfa, 0x85, 0x0f, 0x5c,
    0x97, 0x61, 0xbf, 0x46, 0x7e, 0xec, 0xd6, 0x64, 0xda, 0xa9, 0x8e, 0xf5,
    0xd3, 0xdf, 0xfa, 0x13, 0x5a, 0xb2, 0x3e, 0xeb, 0x0a, 0x9d, 0x02, 0xc0,
    0x33, 0xec, 0x2a, 0x70, 0x80, 0x85, 0x35, 0x04, 0x7b, 0xfc, 0x0a, 0x6c,
    0xb4, 0x10, 0x2d, 0x4a, 0xbe, 0x35, 0x78, 0x41, 0x3a, 0xc6, 0x01, 0x3a,
    0x59, 0x21, 0x17, 0x04, 0x60, 0x6a, 0x51, 0x6c, 0x84, 0xde, 0xc3, 0x3b,
    0x1e, 0x6a, 0xaf, 0x82, 0x5d, 0x81, 0xe2, 0x44, 0x25, 0x98, 0x89, 0xdb,
    0x82, 0x17, 0xe6, 0xb8, 0x9f, 0xfd, 0x03, 0x86, 0x63, 0x8c, 0xe1, 0x93,
    0x77, 0x61, 0x3c, 0xc2, 0x75, 0x14, 0xa1, 0xc2,
    // B, K
    0x09, 0x0d, 0x6f, 0x82, 0x77, 0x88, 0x49, 0x53, 0xba, 0x1e, 0x1b, 0x0e,
    0x5e, 0xae, 0xc0, 0x27, 0xad, 0xe3, 0xb1, 0x09, 0x4f, 0xcd, 0xb6, 0xe6,
    0x6f, 0x7f, 0xa3, 0x1a, 0x1e, 0xfb, 0x52, 0x72, 0xfa, 0x85, 0x0f, 0x5c,
    0x97, 0x61, 0xbf, 0x46, 0x7e, 0xec, 0xd6, 0x64, 0xda, 0xa9, 0x8e, 0xf5,
    0xd3, 0xdf, 0xfa, 0x13, 0x5a, 0xb2, 0x3e, 0xeb, 0x0a, 0x9d, 0x02, 0xc0,
    0x33, 0xec, 0x2a, 0x70, 0x95, 0x8b, 0x05, 0x1e, 0x8b, 0xa5, 0x21, 0xdd,
    0x63, 0xfd, 0x1a, 0x36, 0xb7, 0x42, 0x04, 0x92, 0x10, 0xe6, 0x29, 0x22,
    0xc8, 0x97, 0xb1, 0x28, 0x01, 0x45, 0x95, 0xf1, 0x2a, 0xa0, 0x86, 0x41,
    0xc4, 0x4c, 0xb6, 0x3b, 0x45, 0x23, 0x6e, 0x8d, 0x6e, 0x07, 0xc7, 0x5b,
    0xe5, 0x46, 0xca, 0xd0, 0x68, 0x99, 0xb6, 0x30, 0x7b, 0x70, 0xb0, 0x92,
    0x48, 0xc2, 0x89, 0xb6, 0x27, 0x3b, 0x95, 0x89};

const std::vector<uint8_t> Epid11FileParser::kEmptyGroupRlFile = {
    // Epid version
    0x01, 0x00,
    // Epid type
    0x00, 0x0f,
    // RL ver
    0x00, 0x00, 0x00, 0x00,
    // n3
    0x00, 0x00, 0x00, 0x00,
    // Signature
    0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a,
    0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06,
    0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0xc3, 0x21, 0x99, 0xe1,
    0x18, 0x22, 0x4a, 0xd2, 0xa5, 0xe5, 0xbf, 0x4a, 0xd9, 0x83, 0x08, 0x9d,
    0x62, 0x71, 0xa1, 0x39, 0x21, 0x49, 0x5d, 0xb2, 0x7a, 0xdb, 0x05, 0x2a,
    0xa4, 0xde, 0xb0, 0xac};
const std::vector<uint8_t> Epid11FileParser::kEmptyGroupRl = {
    // RL ver
    0x00, 0x00, 0x00, 0x00,
    // n3
    0x00, 0x00, 0x00, 0x00};

const std::vector<uint8_t> Epid11FileParser::kShortGroupRlFile = {
    // Epid version
    0x01, 0x00,
    // Epid type
    0x00, 0x0f,
    // RL ver
    0x00, 0x00, 0x00, 0x03,
    // n3
    0x00, 0x00, 0x00, 0x03,
    // GIDs
    0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03,
    // Signature
    0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed, 0x2a,
    0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a, 0x6c, 0x06,
    0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0xc0, 0xec, 0x90, 0x92,
    0xe9, 0xaa, 0x2e, 0x61, 0xca, 0x70, 0x8f, 0x48, 0xd4, 0x7d, 0xe7, 0x82,
    0x22, 0x9f, 0x2f, 0x78, 0x5b, 0xfe, 0x56, 0x6e, 0x1a, 0xa1, 0x69, 0x9d,
    0xcc, 0xb1, 0xaa, 0x62};
const std::vector<uint8_t> Epid11FileParser::kShortGroupRl = {
    // RL ver
    0x00, 0x00, 0x00, 0x03,
    // n3
    0x00, 0x00, 0x00, 0x03,
    // GIDs
    0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03};

//////////////////////////////////////////////////////////////////////////
// Epid11ParseGroupPubKeyFile Tests
TEST_F(Epid11FileParser, GroupPubKeyParseFailsGivenNullParameters) {
  Epid11GroupPubKey pubkey{};
  EXPECT_EQ(kEpidBadArgErr, Epid11ParseGroupPubKeyFile(
                                nullptr, this->kGroupPublicKeyFile.size(),
                                &this->kCert, &pubkey));
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
                                       this->kGroupPublicKeyFile.size(),
                                       nullptr, &pubkey));
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
                                       this->kGroupPublicKeyFile.size(),
                                       &this->kCert, nullptr));
}

TEST_F(Epid11FileParser, GroupPubKeyParseFailsGivenUnsupportedCurve) {
  Epid11GroupPubKey pubkey{};
  EpidCaCertificate unsupported_curve1(this->kCert);
  unsupported_curve1.a.data[0] = unsupported_curve1.a.data[0] ^ 0xFF;
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
                                       this->kGroupPublicKeyFile.size(),
                                       &unsupported_curve1, &pubkey));
  EpidCaCertificate unsupported_curve2(this->kCert);
  unsupported_curve2.b.data[0] = unsupported_curve2.b.data[0] ^ 0xFF;
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
                                       this->kGroupPublicKeyFile.size(),
                                       &unsupported_curve2, &pubkey));
  EpidCaCertificate unsupported_curve3(this->kCert);
  unsupported_curve3.x.data[0] = unsupported_curve3.x.data[0] ^ 0xFF;
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
                                       this->kGroupPublicKeyFile.size(),
                                       &unsupported_curve3, &pubkey));
  EpidCaCertificate unsupported_curve4(this->kCert);
  unsupported_curve4.y.data[0] = unsupported_curve4.y.data[0] ^ 0xFF;
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
                                       this->kGroupPublicKeyFile.size(),
                                       &unsupported_curve4, &pubkey));
  EpidCaCertificate unsupported_curve5(this->kCert);
  unsupported_curve5.r.data[0] = unsupported_curve5.r.data[0] ^ 0xFF;
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
                                       this->kGroupPublicKeyFile.size(),
                                       &unsupported_curve5, &pubkey));
  EpidCaCertificate unsupported_curve6(this->kCert);
  unsupported_curve6.prime.data[0] = unsupported_curve6.prime.data[0] ^ 0xFF;
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
                                       this->kGroupPublicKeyFile.size(),
                                       &unsupported_curve6, &pubkey));
}

TEST_F(Epid11FileParser, GroupPubKeyParseFailsGivenInvalidKeyInCertificate) {
  Epid11GroupPubKey pubkey{};
  EpidCaCertificate invalid_key_qx(this->kCert);
  invalid_key_qx.pubkey.data[0] = invalid_key_qx.pubkey.data[0] ^ 0xFF;
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
                                       this->kGroupPublicKeyFile.size(),
                                       &invalid_key_qx, &pubkey));
  EpidCaCertificate invalid_key_qy(this->kCert);
  invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] =
      invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] ^ 0xFF;
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
                                       this->kGroupPublicKeyFile.size(),
                                       &invalid_key_qy, &pubkey));
  EpidCaCertificate invalid_key_qx_qy(this->kCert);
  invalid_key_qx_qy.pubkey.data[0] = invalid_key_qx_qy.pubkey.data[0] ^ 0xFF;
  invalid_key_qx_qy.pubkey.data[sizeof(invalid_key_qx_qy.pubkey) - 1] =
      invalid_key_qx_qy.pubkey.data[sizeof(invalid_key_qx_qy.pubkey) - 1] ^
      0xFF;
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
                                       this->kGroupPublicKeyFile.size(),
                                       &invalid_key_qx_qy, &pubkey));
}

TEST_F(Epid11FileParser, RejectsGroupPubKeyFileWithInvalidSize) {
  Epid11GroupPubKey pubkey{};
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
                                       0, &this->kCert, &pubkey));
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupPubKeyFile((void*)this->kGroupPublicKeyFile.data(),
                                       this->kGroupPublicKeyFile.size() - 1,
                                       &this->kCert, &pubkey));
}

TEST_F(Epid11FileParser, RejectsInvalidGroupPubKeyFileType) {
  Epid11GroupPubKey pubkey{};
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupPubKeyFile((void*)this->kShortPrivRlFile.data(),
                                       this->kGroupPublicKeyFile.size(),
                                       &this->kCert, &pubkey));
}

TEST_F(Epid11FileParser, RejectsGroupPubKeyFileWithUnsupportedEpidVersion) {
  Epid11GroupPubKey pubkey{};

  std::vector<uint8_t> unsupported_epidver_file(this->kGroupPublicKeyFile);
  unsupported_epidver_file[0] = {0x02};
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupPubKeyFile((void*)unsupported_epidver_file.data(),
                                       unsupported_epidver_file.size(),
                                       &this->kCert, &pubkey));
}

TEST_F(Epid11FileParser, ParsesValidPubKeyFile) {
  std::vector<uint8_t> pubkey(sizeof(Epid11GroupPubKey), 0);
  EXPECT_EQ(kEpidNoErr, Epid11ParseGroupPubKeyFile(
                            (void*)this->kGroupPublicKeyFile.data(),
                            this->kGroupPublicKeyFile.size(), &this->kCert,
                            (Epid11GroupPubKey*)pubkey.data()));
  EXPECT_EQ(this->kGroupPublicKey, pubkey);
}

TEST_F(Epid11FileParser, ParsesValidMultiPubKeyFile) {
  std::vector<uint8_t> pubkey(sizeof(Epid11GroupPubKey), 0);
  EXPECT_EQ(kEpidNoErr, Epid11ParseGroupPubKeyFile(
                            (void*)this->kGroupMultiPublicKeyFile.data(),
                            this->kGroupMultiPublicKeyFile.size(), &this->kCert,
                            (Epid11GroupPubKey*)pubkey.data()));
  EXPECT_EQ(this->kGroupPublicKey, pubkey);
}

TEST_F(Epid11FileParser, RejectsGroupPubKeyFileWithInvalidSignature) {
  Epid11GroupPubKey pubkey{};
  std::vector<uint8_t> pubkey_inv_sign(this->kGroupPublicKeyFile);
  pubkey_inv_sign[pubkey_inv_sign.size() - 1] =
      pubkey_inv_sign[pubkey_inv_sign.size() - 1] ^ 0xFF;
  EXPECT_EQ(kEpidSigInvalid,
            Epid11ParseGroupPubKeyFile((void*)pubkey_inv_sign.data(),
                                       pubkey_inv_sign.size(), &this->kCert,
                                       &pubkey));
}

//////////////////////////////////////////////////////////////////////////
// Epid11ParsePrivRlFile Tests
TEST_F(Epid11FileParser, PrivRlParseProvidesRequiredLenWithNullDest) {
  size_t rl_len = 0;
  EXPECT_EQ(kEpidNoErr,
            Epid11ParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
                                  this->kShortPrivRlFile.size(), &this->kCert,
                                  nullptr, &rl_len));
  EXPECT_EQ(this->kShortPrivRl.size(), rl_len);
}

TEST_F(Epid11FileParser, PrivRlParseFailsGivenNullParameters) {
  size_t rl_len = this->kShortPrivRl.size();
  std::vector<uint8_t> rl(rl_len);

  // null input buffer
  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParsePrivRlFile(nullptr, this->kShortPrivRlFile.size(),
                            &this->kCert, (Epid11PrivRl*)rl.data(), &rl_len));
  // null kCert
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
                                  this->kShortPrivRlFile.size(), nullptr,
                                  (Epid11PrivRl*)rl.data(), &rl_len));
  // null rl_length
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
                                  this->kShortPrivRlFile.size(), &this->kCert,
                                  (Epid11PrivRl*)rl.data(), nullptr));
  // null rl_length with null dest
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
                                  this->kShortPrivRlFile.size(), &this->kCert,
                                  nullptr, nullptr));
}

TEST_F(Epid11FileParser, PrivRlParseFailsGivenUnsupportedCurveInCA) {
  size_t rl_len = this->kShortPrivRl.size();
  std::vector<uint8_t> rl(rl_len);
  EpidCaCertificate unsupported_curve(kCert);
  unsupported_curve.a.data[0] = unsupported_curve.a.data[0] ^ 0xFF;

  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
                            this->kShortPrivRlFile.size(), &unsupported_curve,
                            (Epid11PrivRl*)rl.data(), &rl_len));
  EpidCaCertificate unsupported_curve2(kCert);
  unsupported_curve2.b.data[0] = unsupported_curve2.b.data[0] ^ 0xFF;

  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
                            this->kShortPrivRlFile.size(), &unsupported_curve2,
                            (Epid11PrivRl*)rl.data(), &rl_len));
  EpidCaCertificate unsupported_curve3(kCert);
  unsupported_curve3.x.data[0] = unsupported_curve3.x.data[0] ^ 0xFF;

  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
                            this->kShortPrivRlFile.size(), &unsupported_curve3,
                            (Epid11PrivRl*)rl.data(), &rl_len));
  EpidCaCertificate unsupported_curve4(kCert);
  unsupported_curve4.y.data[0] = unsupported_curve4.y.data[0] ^ 0xFF;

  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
                            this->kShortPrivRlFile.size(), &unsupported_curve4,
                            (Epid11PrivRl*)rl.data(), &rl_len));
  EpidCaCertificate unsupported_curve5(kCert);
  unsupported_curve5.r.data[0] = unsupported_curve5.r.data[0] ^ 0xFF;

  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
                            this->kShortPrivRlFile.size(), &unsupported_curve5,
                            (Epid11PrivRl*)rl.data(), &rl_len));
  EpidCaCertificate unsupported_curve6(kCert);
  unsupported_curve6.prime.data[0] = unsupported_curve6.prime.data[0] ^ 0xFF;

  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
                            this->kShortPrivRlFile.size(), &unsupported_curve6,
                            (Epid11PrivRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, PrivRlParseFailsGivenInvalidKeyInCertificate) {
  size_t rl_len = this->kShortPrivRl.size();
  std::vector<uint8_t> rl(rl_len);
  EpidCaCertificate invalid_key_qx(kCert);
  invalid_key_qx.pubkey.data[0] = invalid_key_qx.pubkey.data[0] ^ 0xFF;

  EXPECT_EQ(kEpidBadArgErr, Epid11ParsePrivRlFile(
                                (void*)this->kShortPrivRlFile.data(),
                                this->kShortPrivRlFile.size(), &invalid_key_qx,
                                (Epid11PrivRl*)rl.data(), &rl_len));

  EpidCaCertificate invalid_key_qy(kCert);
  invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] =
      invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] ^ 0xFF;

  EXPECT_EQ(kEpidBadArgErr, Epid11ParsePrivRlFile(
                                (void*)this->kShortPrivRlFile.data(),
                                this->kShortPrivRlFile.size(), &invalid_key_qy,
                                (Epid11PrivRl*)rl.data(), &rl_len));

  EpidCaCertificate invalid_key_qx_qy(kCert);
  invalid_key_qx_qy.pubkey.data[0] = invalid_key_qx_qy.pubkey.data[0] ^ 0xFF;
  invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] =
      invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] ^ 0xFF;
  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
                            this->kShortPrivRlFile.size(), &invalid_key_qx_qy,
                            (Epid11PrivRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, PrivRlParseRejectsPrivRlFileWithInvalidSize) {
  size_t rl_len = this->kEmptyPrivRl.size();
  std::vector<uint8_t> rl(rl_len);

  EXPECT_EQ(kEpidBadArgErr, Epid11ParsePrivRlFile(
                                (void*)this->kEmptyPrivRlFile.data(),
                                this->kEmptyPrivRlFile.size() + 1, &this->kCert,
                                (Epid11PrivRl*)rl.data(), &rl_len));

  EXPECT_EQ(kEpidBadArgErr, Epid11ParsePrivRlFile(
                                (void*)this->kEmptyPrivRlFile.data(),
                                this->kEmptyPrivRlFile.size() - 1, &this->kCert,
                                (Epid11PrivRl*)rl.data(), &rl_len));
  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParsePrivRlFile((void*)this->kEmptyPrivRlFile.data(), 0,
                            &this->kCert, (Epid11PrivRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, PrivRlParseRejectsInvalidPrivRlFileType) {
  size_t rl_len = this->kShortPrivRl.size();
  std::vector<uint8_t> rl(rl_len);

  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParsePrivRlFile((void*)this->kShortGroupRlFile.data(),
                                  this->kShortGroupRlFile.size(), &this->kCert,
                                  (Epid11PrivRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, PrivRlRejectsPrivRlFileWithUnsupportedEpidVersion) {
  size_t rl_len = this->kShortPrivRl.size();
  std::vector<uint8_t> rl(rl_len);

  std::vector<uint8_t> unsupported_epidver_file(this->kShortPrivRlFile);
  unsupported_epidver_file[0] = {0x02};

  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParsePrivRlFile((void*)unsupported_epidver_file.data(),
                                  unsupported_epidver_file.size(), &this->kCert,
                                  (Epid11PrivRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, PrivRlParseParsesEmptyPrivRl) {
  size_t rl_len = this->kEmptyPrivRl.size();
  std::vector<uint8_t> rl(rl_len);

  EXPECT_EQ(kEpidNoErr,
            Epid11ParsePrivRlFile((void*)this->kEmptyPrivRlFile.data(),
                                  this->kEmptyPrivRlFile.size(), &this->kCert,
                                  (Epid11PrivRl*)rl.data(), &rl_len));
  EXPECT_EQ(this->kEmptyPrivRl, rl);
}

TEST_F(Epid11FileParser, PrivRlParseParsesShortPrivRl) {
  size_t rl_len = this->kShortPrivRl.size();
  std::vector<uint8_t> rl(rl_len);

  EXPECT_EQ(kEpidNoErr,
            Epid11ParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
                                  this->kShortPrivRlFile.size(), &this->kCert,
                                  (Epid11PrivRl*)rl.data(), &rl_len));
  EXPECT_EQ(this->kShortPrivRl, rl);
}

TEST_F(Epid11FileParser, PrivRlParseParsesLongPrivRl) {
  EcdsaSignature signature = {
      0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed,
      0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a,
      0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x31,
      0x02, 0x1e, 0x05, 0xa2, 0x80, 0x99, 0xef, 0xa9, 0xed, 0x69, 0x90,
      0x36, 0x83, 0xaf, 0x95, 0xb8, 0x11, 0x5b, 0xb1, 0x83, 0x5f, 0x86,
      0x6b, 0x82, 0x17, 0x8f, 0x00, 0x3d, 0x79, 0x25, 0xda,
  };

  std::vector<uint8_t> long_privrl_file = {
      // Epid Version
      0x01, 0x00,
      // Epid type
      0x00, 0x0d,
      // GID
      0x00, 0x00, 0x00, 0x7b,
      // RL Ver
      0x00, 0x00, 0x00, 0x03,
      // n1
      0x00, 0x00, 0x00, 0x32,
  };
  const std::vector<uint8_t> FToCreateLongRl = {
      0x00, 0x00, 0x56, 0x1e, 0xb1, 0x91, 0xb6, 0xdf, 0x40, 0xbc, 0xa2,
      0xe3, 0xe3, 0x92, 0x33, 0xd1, 0xd7, 0x5c, 0xcc, 0x4c, 0x3a, 0xe7,
      0x91, 0x49, 0x73, 0xe2, 0x03, 0xd4, 0x5e, 0x4f, 0x87, 0xad,
  };
  for (int i = 0; i < 50; ++i) {
    for (auto it : FToCreateLongRl) {
      long_privrl_file.push_back(it);
    }
  }
  for (auto it : signature.x.data) {
    long_privrl_file.push_back(it);
  }
  for (auto it : signature.y.data) {
    long_privrl_file.push_back(it);
  }
  size_t rl_len = long_privrl_file.size() - 68;
  std::vector<uint8_t> rl(rl_len);

  EXPECT_EQ(kEpidNoErr,
            Epid11ParsePrivRlFile((void*)long_privrl_file.data(),
                                  long_privrl_file.size(), &this->kCert,
                                  (Epid11PrivRl*)rl.data(), &rl_len));
  EXPECT_EQ(
      std::vector<uint8_t>(&long_privrl_file[4],
                           &long_privrl_file[long_privrl_file.size() - 64]),
      rl);
}

TEST_F(Epid11FileParser, PrivRlRejectsPrivRlFileWithInvalidSignature) {
  size_t rl_len = this->kShortPrivRl.size();
  std::vector<uint8_t> rl(rl_len);
  std::vector<uint8_t> privrl_inv_sign(kShortPrivRlFile);
  privrl_inv_sign[privrl_inv_sign.size() - 1] =
      privrl_inv_sign[privrl_inv_sign.size() - 1] ^ 0xFF;

  EXPECT_EQ(
      kEpidSigInvalid,
      Epid11ParsePrivRlFile(privrl_inv_sign.data(), privrl_inv_sign.size(),
                            &this->kCert, (Epid11PrivRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, PrivRlRejectsGivenInsufficientOutputBufSize) {
  size_t rl_len = this->kShortPrivRl.size() - 1;
  std::vector<uint8_t> rl(rl_len);

  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
                                  this->kShortPrivRlFile.size(), &this->kCert,
                                  (Epid11PrivRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, PrivRlReturnsProperSizeGivenOversizedPrivRlBuf) {
  size_t rl_len = this->kShortPrivRl.size() + 1;
  std::vector<uint8_t> oversized_rl(rl_len);

  EXPECT_EQ(kEpidNoErr,
            Epid11ParsePrivRlFile((void*)this->kShortPrivRlFile.data(),
                                  this->kShortPrivRlFile.size(), &this->kCert,
                                  (Epid11PrivRl*)oversized_rl.data(), &rl_len));
  std::vector<uint8_t> rl(oversized_rl.begin(), oversized_rl.end() - 1);
  EXPECT_EQ(this->kShortPrivRl, rl);
  EXPECT_EQ(this->kShortPrivRl.size(), rl_len);
}
//////////////////////////////////////////////////////////////////////////
// Epid11ParseSigRlFile Tests
TEST_F(Epid11FileParser, SigRlParseProvidesRequiredLenWithNullDest) {
  size_t rl_len = 0;
  EXPECT_EQ(kEpidNoErr,
            Epid11ParseSigRlFile((void*)this->kShortSigRlFile.data(),
                                 this->kShortSigRlFile.size(), &kCert, nullptr,
                                 &rl_len));
  EXPECT_EQ(rl_len, this->kShortSigRl.size());
}

TEST_F(Epid11FileParser, SigRlParseFailsGivenNullParameters) {
  size_t rl_len = this->kShortSigRl.size();
  std::vector<uint8_t> rl(rl_len);
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseSigRlFile(nullptr, this->kShortSigRlFile.size(), &kCert,
                                 (Epid11SigRl*)rl.data(), &rl_len));
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseSigRlFile((void*)this->kShortSigRlFile.data(),
                                 this->kShortSigRlFile.size(), nullptr,
                                 (Epid11SigRl*)rl.data(), &rl_len));
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseSigRlFile((void*)this->kShortSigRlFile.data(),
                                 this->kShortSigRlFile.size(), &kCert,
                                 (Epid11SigRl*)rl.data(), nullptr));
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseSigRlFile((void*)this->kShortSigRlFile.data(),
                                 this->kShortSigRlFile.size(), &kCert, nullptr,
                                 nullptr));
}

TEST_F(Epid11FileParser, SigRlParseFailsGivenUnsupportedCurveInCA) {
  size_t rl_len = this->kShortSigRl.size();
  std::vector<uint8_t> rl(rl_len);
  EpidCaCertificate unsupported_curve1(kCert);
  unsupported_curve1.a.data[0] = unsupported_curve1.a.data[0] ^ 0xFF;
  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParseSigRlFile((void*)this->kShortSigRlFile.data(),
                           this->kShortSigRlFile.size(), &unsupported_curve1,
                           (Epid11SigRl*)rl.data(), &rl_len));
  EpidCaCertificate unsupported_curve2(kCert);
  unsupported_curve2.b.data[0] = unsupported_curve2.b.data[0] ^ 0xFF;
  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParseSigRlFile((void*)this->kShortSigRlFile.data(),
                           this->kShortSigRlFile.size(), &unsupported_curve2,
                           (Epid11SigRl*)rl.data(), &rl_len));
  EpidCaCertificate unsupported_curve3(kCert);
  unsupported_curve3.x.data[0] = unsupported_curve3.x.data[0] ^ 0xFF;
  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParseSigRlFile((void*)this->kShortSigRlFile.data(),
                           this->kShortSigRlFile.size(), &unsupported_curve3,
                           (Epid11SigRl*)rl.data(), &rl_len));
  EpidCaCertificate unsupported_curve4(kCert);
  unsupported_curve4.y.data[0] = unsupported_curve4.y.data[0] ^ 0xFF;
  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParseSigRlFile((void*)this->kShortSigRlFile.data(),
                           this->kShortSigRlFile.size(), &unsupported_curve4,
                           (Epid11SigRl*)rl.data(), &rl_len));
  EpidCaCertificate unsupported_curve5(kCert);
  unsupported_curve5.r.data[0] = unsupported_curve5.r.data[0] ^ 0xFF;
  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParseSigRlFile((void*)this->kShortSigRlFile.data(),
                           this->kShortSigRlFile.size(), &unsupported_curve5,
                           (Epid11SigRl*)rl.data(), &rl_len));
  EpidCaCertificate unsupported_curve6(kCert);
  unsupported_curve6.prime.data[0] = unsupported_curve6.prime.data[0] ^ 0xFF;
  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParseSigRlFile((void*)this->kShortSigRlFile.data(),
                           this->kShortSigRlFile.size(), &unsupported_curve6,
                           (Epid11SigRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, SigRlParseFailsGivenInvalidKeyInCertificate) {
  size_t rl_len = this->kShortSigRl.size();
  std::vector<uint8_t> rl(rl_len);
  EpidCaCertificate invalid_key_qx(kCert);
  invalid_key_qx.pubkey.data[0] = invalid_key_qx.pubkey.data[0] ^ 0xFF;
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseSigRlFile((void*)this->kShortSigRlFile.data(),
                                 this->kShortSigRlFile.size(), &invalid_key_qx,
                                 (Epid11SigRl*)rl.data(), &rl_len));
  EpidCaCertificate invalid_key_qy(kCert);
  invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] =
      invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] ^ 0xFF;
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseSigRlFile((void*)this->kShortSigRlFile.data(),
                                 this->kShortSigRlFile.size(), &invalid_key_qy,
                                 (Epid11SigRl*)rl.data(), &rl_len));
  EpidCaCertificate invalid_key_qx_qy(kCert);
  invalid_key_qx_qy.pubkey.data[0] = invalid_key_qx_qy.pubkey.data[0] ^ 0xFF;
  invalid_key_qx_qy.pubkey.data[sizeof(invalid_key_qx_qy.pubkey) - 1] =
      invalid_key_qx_qy.pubkey.data[sizeof(invalid_key_qx_qy.pubkey) - 1] ^
      0xFF;
  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParseSigRlFile((void*)this->kShortSigRlFile.data(),
                           this->kShortSigRlFile.size(), &invalid_key_qx_qy,
                           (Epid11SigRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, SigRlParseRejectsSigRlFileWithInvalidSize) {
  size_t rl_len = this->kEmptySigRl.size();
  std::vector<uint8_t> rl(rl_len);
  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParseSigRlFile((void*)this->kEmptySigRlFile.data(), 0, &this->kCert,
                           (Epid11SigRl*)rl.data(), &rl_len));
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseSigRlFile((void*)this->kEmptySigRlFile.data(),
                                 this->kEmptySigRlFile.size() - 1, &this->kCert,
                                 (Epid11SigRl*)rl.data(), &rl_len));
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseSigRlFile((void*)this->kShortSigRlFile.data(),
                                 this->kEmptySigRlFile.size() + 1, &this->kCert,
                                 (Epid11SigRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, SigRlParseRejectsInvalidSigRlFileType) {
  size_t rl_len = this->kShortPrivRl.size();
  std::vector<uint8_t> rl(rl_len);
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseSigRlFile((void*)this->kShortPrivRlFile.data(),
                                 this->kShortPrivRlFile.size(), &this->kCert,
                                 (Epid11SigRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, RejectsSigRlFileWithUnsupportedEpidVersion) {
  size_t rl_len = this->kShortSigRl.size();
  std::vector<uint8_t> rl(rl_len);
  std::vector<uint8_t> unsupported_epidver_file(this->kShortSigRlFile);
  unsupported_epidver_file[0] = {0x02};
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseSigRlFile((void*)unsupported_epidver_file.data(),
                                 unsupported_epidver_file.size(), &this->kCert,
                                 (Epid11SigRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, SigRlParseParsesEmptySigRl) {
  size_t rl_len = this->kEmptySigRl.size();
  std::vector<uint8_t> rl(rl_len);
  EXPECT_EQ(kEpidNoErr,
            Epid11ParseSigRlFile(this->kEmptySigRlFile.data(),
                                 this->kEmptySigRlFile.size(), &this->kCert,
                                 (Epid11SigRl*)rl.data(), &rl_len));
  EXPECT_EQ(rl, this->kEmptySigRl);
}

TEST_F(Epid11FileParser, SigRlParseParsesShortSigRl) {
  size_t rl_len = this->kShortSigRl.size();
  std::vector<uint8_t> rl(rl_len);
  EXPECT_EQ(kEpidNoErr,
            Epid11ParseSigRlFile(this->kShortSigRlFile.data(),
                                 this->kShortSigRlFile.size(), &this->kCert,
                                 (Epid11SigRl*)rl.data(), &rl_len));
  EXPECT_EQ(rl, this->kShortSigRl);
}

TEST_F(Epid11FileParser, SigRlParseParsesLongSigRl) {
  std::vector<uint8_t> bk = {
      0x09, 0x0d, 0x6f, 0x82, 0x77, 0x88, 0x49, 0x53, 0xba, 0x1e, 0x1b, 0x0e,
      0x5e, 0xae, 0xc0, 0x27, 0xad, 0xe3, 0xb1, 0x09, 0x4f, 0xcd, 0xb6, 0xe6,
      0x6f, 0x7f, 0xa3, 0x1a, 0x1e, 0xfb, 0x52, 0x72, 0xfa, 0x85, 0x0f, 0x5c,
      0x97, 0x61, 0xbf, 0x46, 0x7e, 0xec, 0xd6, 0x64, 0xda, 0xa9, 0x8e, 0xf5,
      0xd3, 0xdf, 0xfa, 0x13, 0x5a, 0xb2, 0x3e, 0xeb, 0x0a, 0x9d, 0x02, 0xc0,
      0x33, 0xec, 0x2a, 0x70, 0x80, 0x85, 0x35, 0x04, 0x7b, 0xfc, 0x0a, 0x6c,
      0xb4, 0x10, 0x2d, 0x4a, 0xbe, 0x35, 0x78, 0x41, 0x3a, 0xc6, 0x01, 0x3a,
      0x59, 0x21, 0x17, 0x04, 0x60, 0x6a, 0x51, 0x6c, 0x84, 0xde, 0xc3, 0x3b,
      0x1e, 0x6a, 0xaf, 0x82, 0x5d, 0x81, 0xe2, 0x44, 0x25, 0x98, 0x89, 0xdb,
      0x82, 0x17, 0xe6, 0xb8, 0x9f, 0xfd, 0x03, 0x86, 0x63, 0x8c, 0xe1, 0x93,
      0x77, 0x61, 0x3c, 0xc2, 0x75, 0x14, 0xa1, 0xc2};
  EcdsaSignature signature = {
      0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed,
      0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a,
      0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x02,
      0x23, 0x1d, 0x31, 0x17, 0x88, 0x49, 0x13, 0x47, 0xe7, 0xda, 0xfe,
      0x8d, 0x67, 0xba, 0x16, 0x1d, 0x0a, 0xd3, 0x4a, 0x2d, 0xd1, 0xf8,
      0x60, 0x21, 0xa5, 0x00, 0x9a, 0x0d, 0x4d, 0xc4, 0xbd};
  std::vector<uint8_t> long_sigrl_file = {// EPID Version
                                          0x01, 0x00,
                                          // Epid type
                                          0x00, 0x0e,
                                          // GID
                                          0x00, 0x00, 0x00, 0x7b,
                                          // RL ver
                                          0x00, 0x00, 0x00, 0x32,
                                          // n2
                                          0x00, 0x00, 0x00, 0x32};
  for (int i = 0; i < 50; ++i) {
    for (auto it : bk) {
      long_sigrl_file.push_back(it);
    }
  }
  for (auto it : signature.x.data) {
    long_sigrl_file.push_back(it);
  }
  for (auto it : signature.y.data) {
    long_sigrl_file.push_back(it);
  }
  size_t rl_len = long_sigrl_file.size() - sizeof(signature) - 4;
  std::vector<uint8_t> rl(rl_len);
  EXPECT_EQ(kEpidNoErr, Epid11ParseSigRlFile(
                            long_sigrl_file.data(), long_sigrl_file.size(),
                            &this->kCert, (Epid11SigRl*)rl.data(), &rl_len));

  std::vector<uint8_t> expected_long_sig_rl(std::vector<uint8_t>(
      &long_sigrl_file[4],
      &long_sigrl_file[long_sigrl_file.size() - sizeof(signature)]));

  EXPECT_EQ(expected_long_sig_rl, rl);
}

TEST_F(Epid11FileParser, RejectsSigRlFileWithInvalidSignature) {
  size_t rl_len = this->kShortSigRl.size();
  std::vector<uint8_t> rl(rl_len);
  std::vector<uint8_t> sigrl_inv_sign(kShortSigRlFile);
  sigrl_inv_sign[sigrl_inv_sign.size() - 1] =
      sigrl_inv_sign[sigrl_inv_sign.size() - 1] ^ 0xFF;
  EXPECT_EQ(
      kEpidSigInvalid,
      Epid11ParseSigRlFile((void*)sigrl_inv_sign.data(), sigrl_inv_sign.size(),
                           &this->kCert, (Epid11SigRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, RejectsGivenInsufficientOutputBufSize) {
  size_t rl_len = this->kShortSigRl.size() - 1;
  std::vector<uint8_t> rl(rl_len);

  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseSigRlFile((void*)this->kShortSigRlFile.data(),
                                 this->kShortSigRlFile.size(), &this->kCert,
                                 (Epid11SigRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, ReturnsProperSizeGivenOversizedSigRlBuf) {
  size_t rl_len = this->kShortSigRl.size() + 1;
  std::vector<uint8_t> oversized_rl(rl_len);

  EXPECT_EQ(kEpidNoErr,
            Epid11ParseSigRlFile((void*)this->kShortSigRlFile.data(),
                                 this->kShortSigRlFile.size(), &this->kCert,
                                 (Epid11SigRl*)oversized_rl.data(), &rl_len));
  std::vector<uint8_t> rl(oversized_rl.begin(), oversized_rl.end() - 1);
  EXPECT_EQ(this->kShortSigRl, rl);
  EXPECT_EQ(this->kShortSigRl.size(), rl_len);
}
//////////////////////////////////////////////////////////////////////////
// Epid11ParseGroupRlFile Tests
TEST_F(Epid11FileParser, GroupRlParseProvidesRequiredLenWithNullDest) {
  size_t rl_len = 0;
  EXPECT_EQ(kEpidNoErr,
            Epid11ParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
                                   this->kShortGroupRlFile.size(), &kCert,
                                   nullptr, &rl_len));
  EXPECT_EQ(this->kShortGroupRl.size(), rl_len);
}

TEST_F(Epid11FileParser, GroupRlParseFailsGivenNullParameters) {
  size_t rl_len = this->kShortGroupRl.size();
  std::vector<uint8_t> rl(rl_len);
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupRlFile(nullptr, this->kShortGroupRlFile.size(),
                                   &kCert, (Epid11GroupRl*)rl.data(), &rl_len));
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
                                   this->kShortGroupRlFile.size(), nullptr,
                                   (Epid11GroupRl*)rl.data(), &rl_len));
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
                                   this->kShortGroupRlFile.size(), &kCert,
                                   (Epid11GroupRl*)rl.data(), nullptr));
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
                                   this->kShortGroupRlFile.size(), &kCert,
                                   nullptr, nullptr));
}

TEST_F(Epid11FileParser, GroupRlParseFailsGivenUnsupportedCurve) {
  size_t rl_len = this->kShortGroupRl.size();
  std::vector<uint8_t> rl(rl_len);
  EpidCaCertificate unsupported_curve1(kCert);
  unsupported_curve1.a.data[0] = unsupported_curve1.a.data[0] ^ 0xFF;
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
                                   this->kShortGroupRlFile.size(),
                                   &unsupported_curve1,
                                   (Epid11GroupRl*)rl.data(), &rl_len));
  EpidCaCertificate unsupported_curve2(kCert);
  unsupported_curve2.b.data[0] = unsupported_curve2.b.data[0] ^ 0xFF;
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
                                   this->kShortGroupRlFile.size(),
                                   &unsupported_curve2,
                                   (Epid11GroupRl*)rl.data(), &rl_len));
  EpidCaCertificate unsupported_curve3(kCert);
  unsupported_curve3.x.data[0] = unsupported_curve3.x.data[0] ^ 0xFF;
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
                                   this->kShortGroupRlFile.size(),
                                   &unsupported_curve3,
                                   (Epid11GroupRl*)rl.data(), &rl_len));
  EpidCaCertificate unsupported_curve4(kCert);
  unsupported_curve4.y.data[0] = unsupported_curve4.y.data[0] ^ 0xFF;
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
                                   this->kShortGroupRlFile.size(),
                                   &unsupported_curve4,
                                   (Epid11GroupRl*)rl.data(), &rl_len));
  EpidCaCertificate unsupported_curve5(kCert);
  unsupported_curve5.r.data[0] = unsupported_curve5.r.data[0] ^ 0xFF;
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
                                   this->kShortGroupRlFile.size(),
                                   &unsupported_curve5,
                                   (Epid11GroupRl*)rl.data(), &rl_len));
  EpidCaCertificate unsupported_curve6(kCert);
  unsupported_curve6.prime.data[0] = unsupported_curve6.prime.data[0] ^ 0xFF;
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
                                   this->kShortGroupRlFile.size(),
                                   &unsupported_curve6,
                                   (Epid11GroupRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, GroupRlParseFailsGivenInvalidKeyInCertificate) {
  size_t rl_len = this->kShortGroupRl.size();
  std::vector<uint8_t> rl(rl_len);
  EpidCaCertificate invalid_key_qx(kCert);
  invalid_key_qx.pubkey.data[0] = invalid_key_qx.pubkey.data[0] ^ 0xFF;
  EXPECT_EQ(kEpidBadArgErr, Epid11ParseGroupRlFile(
                                (void*)this->kShortGroupRlFile.data(),
                                this->kShortGroupRlFile.size(), &invalid_key_qx,
                                (Epid11GroupRl*)rl.data(), &rl_len));
  EpidCaCertificate invalid_key_qy(kCert);
  invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] =
      invalid_key_qy.pubkey.data[sizeof(invalid_key_qy.pubkey) - 1] ^ 0xFF;
  EXPECT_EQ(kEpidBadArgErr, Epid11ParseGroupRlFile(
                                (void*)this->kShortGroupRlFile.data(),
                                this->kShortGroupRlFile.size(), &invalid_key_qy,
                                (Epid11GroupRl*)rl.data(), &rl_len));
  EpidCaCertificate invalid_key_qx_qy(kCert);
  invalid_key_qx_qy.pubkey.data[0] = invalid_key_qx_qy.pubkey.data[0] ^ 0xFF;
  invalid_key_qx_qy.pubkey.data[sizeof(invalid_key_qx_qy.pubkey) - 1] =
      invalid_key_qx_qy.pubkey.data[sizeof(invalid_key_qx_qy.pubkey) - 1] ^
      0xFF;
  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
                             this->kShortGroupRlFile.size(), &invalid_key_qx_qy,
                             (Epid11GroupRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, RejectsGroupRlFileWithInvalidSize) {
  size_t rl_len = this->kEmptyGroupRl.size();
  std::vector<uint8_t> rl(rl_len);
  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParseGroupRlFile((void*)this->kEmptyGroupRlFile.data(), 0,
                             &this->kCert, (Epid11GroupRl*)rl.data(), &rl_len));
  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParseGroupRlFile((void*)this->kEmptyGroupRlFile.data(),
                             this->kEmptyGroupRlFile.size() - 1, &this->kCert,
                             (Epid11GroupRl*)rl.data(), &rl_len));
  EXPECT_EQ(
      kEpidBadArgErr,
      Epid11ParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
                             this->kEmptyGroupRlFile.size() + 1, &this->kCert,
                             (Epid11GroupRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, RejectsInvalidGroupRlFileType) {
  size_t rl_len = this->kShortPrivRl.size();
  std::vector<uint8_t> rl(rl_len);
  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupRlFile((void*)this->kShortPrivRlFile.data(),
                                   this->kShortPrivRlFile.size(), &this->kCert,
                                   (Epid11GroupRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, RejectsGroupRlFileWithUnsupportedEpidVersion) {
  size_t rl_len = this->kShortGroupRl.size();
  std::vector<uint8_t> rl(rl_len);
  std::vector<uint8_t> unsupported_epidver_file(this->kShortGroupRlFile);
  unsupported_epidver_file[0] = {0x02};
  EXPECT_EQ(kEpidBadArgErr, Epid11ParseGroupRlFile(
                                (void*)unsupported_epidver_file.data(),
                                unsupported_epidver_file.size(), &this->kCert,
                                (Epid11GroupRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, ParsesEmptyGroupRl) {
  size_t rl_len = this->kEmptyGroupRl.size();
  std::vector<uint8_t> rl(rl_len);
  EXPECT_EQ(kEpidNoErr,
            Epid11ParseGroupRlFile(this->kEmptyGroupRlFile.data(),
                                   this->kEmptyGroupRlFile.size(), &this->kCert,
                                   (Epid11GroupRl*)rl.data(), &rl_len));
  EXPECT_EQ(rl, this->kEmptyGroupRl);
}

TEST_F(Epid11FileParser, ParsesShortGroupRl) {
  size_t rl_len = this->kShortGroupRl.size();
  std::vector<uint8_t> rl(rl_len);
  EXPECT_EQ(kEpidNoErr,
            Epid11ParseGroupRlFile(this->kShortGroupRlFile.data(),
                                   this->kShortGroupRlFile.size(), &this->kCert,
                                   (Epid11GroupRl*)rl.data(), &rl_len));
  EXPECT_EQ(rl, this->kShortGroupRl);
}

TEST_F(Epid11FileParser, ParsesLongGroupRl) {
  std::vector<uint8_t> gid = {0x00, 0x00, 0x00, 0x01};
  EcdsaSignature signature = {
      0xfb, 0x57, 0x6f, 0x15, 0x3e, 0xf8, 0x41, 0x47, 0x51, 0x71, 0xed,
      0x2a, 0x9b, 0x88, 0x99, 0x5b, 0x85, 0x3b, 0xdf, 0xf9, 0x70, 0x2a,
      0x6c, 0x06, 0x3b, 0x72, 0x02, 0x32, 0xb9, 0x3a, 0x76, 0xe7, 0x64,
      0x0c, 0xa9, 0x25, 0xb2, 0x50, 0xc8, 0xd7, 0x9d, 0xb8, 0xb4, 0x37,
      0x30, 0x90, 0x53, 0x8f, 0x55, 0x50, 0xcf, 0xed, 0x9e, 0xaa, 0x31,
      0x4f, 0x7f, 0xb2, 0x27, 0xf9, 0xbb, 0xfa, 0x52, 0x70};
  std::vector<uint8_t> long_grouprl_file = {
      /// EPID version
      0x01, 0x00,
      // File type
      0x00, 0x0f,
      // RL ver
      0x00, 0x00, 0x00, 0x32,
      // n3
      0x00, 0x00, 0x00, 0x32,
  };
  for (int i = 0; i < 50; ++i) {
    for (auto it : gid) {
      long_grouprl_file.push_back(it);
    }
    gid[3]++;
  }
  for (auto it : signature.x.data) {
    long_grouprl_file.push_back(it);
  }
  for (auto it : signature.y.data) {
    long_grouprl_file.push_back(it);
  }

  size_t rl_len = long_grouprl_file.size() - sizeof(signature) - 4;
  std::vector<uint8_t> rl(rl_len);
  EXPECT_EQ(kEpidNoErr, Epid11ParseGroupRlFile(
                            long_grouprl_file.data(), long_grouprl_file.size(),
                            &this->kCert, (Epid11GroupRl*)rl.data(), &rl_len));

  std::vector<uint8_t> expected_long_gr_rl(std::vector<uint8_t>(
      &long_grouprl_file[4],
      &long_grouprl_file[long_grouprl_file.size() - sizeof(signature)]));

  EXPECT_EQ(expected_long_gr_rl, rl);
}

TEST_F(Epid11FileParser, RejectsGroupRlFileWithInvalidSignature) {
  size_t rl_len = this->kShortGroupRl.size();
  std::vector<uint8_t> rl(rl_len);
  std::vector<uint8_t> grouprl_inv_sign(this->kShortGroupRlFile);
  grouprl_inv_sign[grouprl_inv_sign.size() - 1] =
      grouprl_inv_sign[grouprl_inv_sign.size() - 1] ^ 0xFF;
  EXPECT_EQ(kEpidSigInvalid,
            Epid11ParseGroupRlFile((void*)grouprl_inv_sign.data(),
                                   grouprl_inv_sign.size(), &this->kCert,
                                   (Epid11GroupRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, GroupRlParseRejectsBufWithInsufficientSize) {
  size_t rl_len = this->kShortGroupRl.size() - 1;
  std::vector<uint8_t> rl(rl_len);

  EXPECT_EQ(kEpidBadArgErr,
            Epid11ParseGroupRlFile((void*)this->kShortGroupRlFile.data(),
                                   this->kShortGroupRlFile.size(), &this->kCert,
                                   (Epid11GroupRl*)rl.data(), &rl_len));
}

TEST_F(Epid11FileParser, ReturnsProperSizeGivenOversizedGroupRlBuf) {
  size_t rl_len = this->kShortGroupRl.size() + 1;
  std::vector<uint8_t> oversized_rl(rl_len);

  EXPECT_EQ(kEpidNoErr, Epid11ParseGroupRlFile(
                            (void*)this->kShortGroupRlFile.data(),
                            this->kShortGroupRlFile.size(), &this->kCert,
                            (Epid11GroupRl*)oversized_rl.data(), &rl_len));
  std::vector<uint8_t> rl(oversized_rl.begin(), oversized_rl.end() - 1);
  EXPECT_EQ(this->kShortGroupRl, rl);
  EXPECT_EQ(this->kShortGroupRl.size(), rl_len);
}

}  // namespace
