<commit_before>/*
 * Copyright 2020 Google LLC
 *
 * 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.
 */

#include "ecclesia/magent/sysmodel/x86/fru.h"

#include <cstddef>
#include <cstdint>
#include <fstream>
#include <iterator>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "absl/container/flat_hash_map.h"
#include "absl/status/status.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "ecclesia/magent/lib/eeprom/smbus_eeprom.h"
#include "ecclesia/magent/lib/fru/fru.h"
#include "ecclesia/magent/lib/ipmi/ipmi.h"

namespace ecclesia {

namespace {

constexpr int kFruCommonHeaderSize = 8;
constexpr int kFruBoardInfoAreaSizeIndex = 9;

// Given an input string, returns a new string that contains only the portion
// of the string up to (but not including) the first NUL character. If the
// input string contains no NUL characters than the returned value will be
// equal to the input.
//
// The implementation is intended to be equivalent to:
//    return s.c_str();
// but we want to avoid this because many linting tools will (correctly) flag
// string -> char* -> string conversions as possible bugs.

std::string StringUpToNul(const std::string &s) {
  return s.substr(0, s.find('\0'));
}

absl::Status ValidateFruCommonHeader(
    absl::Span<const unsigned char> common_header) {
  uint8_t sum = 0;

  for (size_t i = 0; i < common_header.size(); i++) {<commit_msg>Internal change<commit_after>/*
 * Copyright 2020 Google LLC
 *
 * 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.
 */

#include "ecclesia/magent/sysmodel/x86/fru.h"

#include <cstddef>
#include <cstdint>
#include <fstream>
#include <iterator>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "absl/container/flat_hash_map.h"
#include "absl/status/status.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "absl/types/span.h"
#include "ecclesia/magent/lib/eeprom/smbus_eeprom.h"
#include "ecclesia/magent/lib/fru/fru.h"
#include "ecclesia/magent/lib/ipmi/ipmi.h"

namespace ecclesia {

namespace {

constexpr int kFruCommonHeaderSize = 8;
constexpr int kFruBoardInfoAreaSizeIndex = 9;

// Given an input string, returns a new string that contains only the portion
// of the string up to (but not including) the first NUL character. If the
// input string contains no NUL characters than the returned value will be
// equal to the input.
//
// The implementation is intended to be equivalent to:
//    return s.c_str();
// but we want to avoid this because many linting tools will (correctly) flag
// string -> char* -> string conversions as possible bugs.

inline std::string StringUpToNul(std::string s) {
  auto iter = s.find('\0');
  if (iter == std::string::npos) {
    // If there is no null, just return the string.
    return s;
  }
  return s.substr(0, iter);
}

absl::Status ValidateFruCommonHeader(
    absl::Span<const unsigned char> common_header) {
  uint8_t sum = 0;

  for (size_t i = 0; i < common_header.size(); i++) {
{'fraction_non_alphanumeric': 0.10936365835954512, 'fraction_numerical': 0.008226469876602952, 'mean_word_length': 4.1610486891385765, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4993163', 'n_tokens_mistral': 1320, 'n_tokens_neox': 1299, 'n_words': 470}