//@ts-nocheck
import * as _m0 from "protobufjs/minimal";
import { isSet, bytesFromBase64, base64FromBytes } from "../../../helpers";
/** PubKey defines an authn public key */

/** PubKey defines an authn public key */

function createBaseAuthnPubKey() {
  return {
    keyId: "",
    coseAlgorithm: 0,
    key: new Uint8Array()
  };
}
export const AuthnPubKey = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.keyId !== "") {
      writer.uint32(10).string(message.keyId);
    }
    if (message.coseAlgorithm !== 0) {
      writer.uint32(16).int32(message.coseAlgorithm);
    }
    if (message.key.length !== 0) {
      writer.uint32(26).bytes(message.key);
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseAuthnPubKey();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.keyId = reader.string();
          break;
        case 2:
          message.coseAlgorithm = reader.int32();
          break;
        case 3:
          message.key = reader.bytes();
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON(object) {
    return {
      keyId: isSet(object.keyId) ? String(object.keyId) : "",
      coseAlgorithm: isSet(object.coseAlgorithm) ? Number(object.coseAlgorithm) : 0,
      key: isSet(object.key) ? bytesFromBase64(object.key) : new Uint8Array()
    };
  },
  toJSON(message) {
    const obj = {};
    message.keyId !== undefined && (obj.keyId = message.keyId);
    message.coseAlgorithm !== undefined && (obj.coseAlgorithm = Math.round(message.coseAlgorithm));
    message.key !== undefined && (obj.key = base64FromBytes(message.key !== undefined ? message.key : new Uint8Array()));
    return obj;
  },
  fromPartial(object) {
    var _object$keyId, _object$coseAlgorithm, _object$key;
    const message = createBaseAuthnPubKey();
    message.keyId = (_object$keyId = object.keyId) !== null && _object$keyId !== void 0 ? _object$keyId : "";
    message.coseAlgorithm = (_object$coseAlgorithm = object.coseAlgorithm) !== null && _object$coseAlgorithm !== void 0 ? _object$coseAlgorithm : 0;
    message.key = (_object$key = object.key) !== null && _object$key !== void 0 ? _object$key : new Uint8Array();
    return message;
  }
};