LCOV - code coverage report
Current view: top level - server/approval - PatchSetApprovalUuidGeneratorImpl.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 10 10 100.0 %
Date: 2022-11-19 15:00:39 Functions: 2 2 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2021 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.server.approval;
      16             : 
      17             : import com.google.gerrit.entities.Account;
      18             : import com.google.gerrit.entities.PatchSet;
      19             : import com.google.gerrit.entities.PatchSetApproval;
      20             : import com.google.gerrit.entities.PatchSetApproval.UUID;
      21             : import com.google.inject.Singleton;
      22             : import java.security.MessageDigest;
      23             : import java.time.Instant;
      24             : import org.eclipse.jgit.lib.Constants;
      25             : import org.eclipse.jgit.lib.ObjectId;
      26             : 
      27             : /**
      28             :  * Default implementation of {@link
      29             :  * com.google.gerrit.server.approval.PatchSetApprovalUuidGenerator}.
      30             :  */
      31             : @Singleton
      32         103 : public class PatchSetApprovalUuidGeneratorImpl implements PatchSetApprovalUuidGenerator {
      33             :   @Override
      34             :   public UUID get(
      35             :       PatchSet.Id patchSetId, Account.Id accountId, String label, short value, Instant granted) {
      36          67 :     MessageDigest md = Constants.newMessageDigest();
      37          67 :     md.update(
      38          67 :         Constants.encode("patchSetId " + patchSetId.getCommaSeparatedChangeAndPatchSetId() + "\n"));
      39          67 :     md.update(Constants.encode("accountId " + accountId + "\n"));
      40          67 :     md.update(Constants.encode("label " + label + "\n"));
      41          67 :     md.update(Constants.encode("value " + value + "\n"));
      42          67 :     md.update(Constants.encode("granted " + granted.toEpochMilli() + "\n"));
      43          67 :     md.update(Constants.encode(String.valueOf(Math.random())));
      44          67 :     return PatchSetApproval.uuid(ObjectId.fromRaw(md.digest()).name());
      45             :   }
      46             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750