1
#pragma once
2

            
3
// Copyright 2018 Google LLC
4
// Copyright Envoy Project Authors
5
// SPDX-License-Identifier: Apache-2.0
6

            
7
#pragma once
8

            
9
#include "source/common/protobuf/protobuf.h"
10

            
11
namespace Envoy {
12
namespace JwtVerify {
13

            
14
class StructUtils {
15
public:
16
  StructUtils(const Protobuf::Struct& struct_pb);
17

            
18
  enum FindResult {
19
    OK = 0,
20
    MISSING,
21
    WRONG_TYPE,
22
    OUT_OF_RANGE,
23
  };
24

            
25
  FindResult GetString(const std::string& name, std::string* str_value);
26

            
27
  // Return error if the JSON value is not within a positive 64 bit integer
28
  // range. The decimals in the JSON value are dropped.
29
  FindResult GetUInt64(const std::string& name, uint64_t* int_value);
30

            
31
  FindResult GetDouble(const std::string& name, double* double_value);
32

            
33
  FindResult GetBoolean(const std::string& name, bool* bool_value);
34

            
35
  // Get string or list of string, designed to get "aud" field
36
  // "aud" can be either string array or string.
37
  // Try as string array, read it as empty array if doesn't exist.
38
  FindResult GetStringList(const std::string& name, std::vector<std::string>* list);
39

            
40
  // Find the value with nested names.
41
  FindResult GetValue(const std::string& nested_names, const Protobuf::Value*& found);
42

            
43
private:
44
  const Protobuf::Struct& struct_pb_;
45
};
46

            
47
} // namespace JwtVerify
48
} // namespace Envoy