package com.github.tomitakussaari.phaas.model;

import com.github.tomitakussaari.phaas.util.CryptoHelper;
import lombok.Data;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.password.PasswordEncoder;

@RequiredArgsConstructor
@Getter
public class DataProtectionScheme {

    public static final String TOKEN_VALUE_SEPARATOR = ".";
    public static final String ESCAPED_TOKEN_VALUE_SEPARATOR = "\\" + TOKEN_VALUE_SEPARATOR;

    private final int id;
    @NonNull
    private final PasswordEncodingAlgorithm algorithm;
    @NonNull
    private final String encryptedKeyWithSalt;
    @NonNull
    private final CryptoHelper cryptoHelper;

    public PasswordEncoder passwordEncoder() {
        return algorithm.encoder();
    }

    public PublicProtectionScheme toPublicScheme() {
        return new PublicProtectionScheme(id, algorithm);
    }

    public CryptoData cryptoData(CharSequence userPassword) {
        return new CryptoData(this, userPassword);
    }

    @RequiredArgsConstructor
    public static class CryptoData {
        private final DataProtectionScheme scheme;
        private final CharSequence userPassword;
        @Getter(lazy = true)
        private final String dataProtectionKey  = dataProtectionKey();

        public DataProtectionScheme getScheme() {
            return scheme;
        }

        private String dataProtectionKey() {
            return scheme.cryptoHelper.decryptData(userPassword, scheme.getEncryptedKeyWithSalt());
        }
    }

    @Data
    public static class PublicProtectionScheme {
        private final int id;
        @NonNull
        private final PasswordEncodingAlgorithm algorithm;
    }


}

@@ -772,25 +772,28 @@
  return 
-a
+getA
 lgorithm
 .encoder
@@ -784,16 +784,18 @@
 lgorithm
+()
 .encoder
@@ -1469,17 +1469,20 @@
  scheme.
-c
+getC
 ryptoHel
@@ -1484,16 +1484,18 @@
 toHelper
+()
 .decrypt

Use getters in DataProtectionScheme