---
title: llarp/service/auth.hpp

---

# llarp/service/auth.hpp



## Namespaces

| Name           |
| -------------- |
| **[llarp](Namespaces/namespacellarp.md)** <br>[crypto.hpp] |
| **[llarp::service](Namespaces/namespacellarp_1_1service.md)**  |

## Classes

|                | Name           |
| -------------- | -------------- |
| struct | **[llarp::service::AuthResult](Classes/structllarp_1_1service_1_1AuthResult.md)** <br>auth result object with code and reason  |
| struct | **[llarp::service::IAuthPolicy](Classes/structllarp_1_1service_1_1IAuthPolicy.md)**  |
| struct | **[llarp::service::AuthInfo](Classes/structllarp_1_1service_1_1AuthInfo.md)** <br>info needed by clients in order to authenticate to a remote endpoint  |




## Source code

```cpp
#pragma once
#include <optional>
#include <string>
#include <functional>
#include "address.hpp"
#include "handler.hpp"
#include <llarp/crypto/types.hpp>

namespace llarp::service
{
  enum class AuthResultCode : uint64_t
  {
    eAuthAccepted = 0,
    eAuthRejected = 1,
    eAuthFailed = 2,
    eAuthRateLimit = 3,
    eAuthPaymentRequired = 4
  };

  uint64_t
  AuthResultCodeAsInt(AuthResultCode code);

  std::optional<AuthResultCode>
  AuthResultCodeFromInt(uint64_t code);

  struct AuthResult
  {
    AuthResultCode code;
    std::string reason;
  };

  std::optional<AuthResultCode>
  ParseAuthResultCode(std::string data);

  struct IAuthPolicy
  {
    virtual ~IAuthPolicy() = default;

    virtual void
    AuthenticateAsync(
        std::shared_ptr<ProtocolMessage> msg, std::function<void(AuthResult)> hook) = 0;

    virtual bool
    AsyncAuthPending(ConvoTag tag) const = 0;
  };

  struct AuthInfo
  {
    std::string token;
  };

  enum class AuthType
  {
    eAuthTypeNone,
    eAuthTypeWhitelist,
    eAuthTypeLMQ,
    eAuthTypeFile,
  };

  enum class AuthFileType
  {
    eAuthFilePlain,
    eAuthFileHashes,
  };

  AuthType
  ParseAuthType(std::string arg);

  AuthFileType
  ParseAuthFileType(std::string arg);

  std::shared_ptr<IAuthPolicy>
  MakeFileAuthPolicy(AbstractRouter*, std::set<fs::path> files, AuthFileType fileType);

}  // namespace llarp::service
```


-------------------------------

Updated on 2022-08-30 at 18:09:28 +0000
