1/* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15
16#include "tensorflow/lite/tools/verifier_internal.h"
17
18#include "tensorflow/lite/schema/schema_generated.h"
19
20namespace tflite {
21namespace internal {
22
23// Verifies flatbuffer format of the model contents and returns the in-memory
24// model.
25const Model* VerifyFlatBufferAndGetModel(const void* buf, size_t len) {
26 ::flatbuffers::Verifier verifier(static_cast<const uint8_t*>(buf), len);
27 if (VerifyModelBuffer(verifier)) {
28 return ::tflite::GetModel(buf);
29 } else {
30 return nullptr;
31 }
32}
33
34} // namespace internal
35} // namespace tflite
36