Class SDObjectEncoder

java.lang.Object
com.authlete.sd.SDObjectEncoder

public class SDObjectEncoder extends Object
A utility to make elements in a map or a list selectively-disclosable recursively.

Decoy digests are automatically added unless decoy magnification ratio is set to 0.0 through constructors or the setDecoyMagnification(double, double) method.

Some claims such as "iss" and "iat" are retained without being made selectively-disclosable. See the description of the getRetainedClaims() method for details.

 // Original dataset
 //
 //   {
 //     "key-1": "value-1",
 //     "key-2": [
 //       "element-1",
 //       "element-2"
 //     ],
 //     "key-3": {
 //       "sub-key-1": "sub-value-1",
 //       "sub-key-2": "sub-value-2",
 //     },
 //   }
 //
 
 List<String> sublist = List.of(
         "element-1",
         "element-2"
 );

 Map<String, String> submap = Map.of(
         "sub-key-1", "sub-value-1",
         "sub-key-2", "sub-value-2"
 );

 Map<String, Object> originalMap = Map.of(
         "key-1", "value-1",
         "key-2", sublist,
         "key-3", submap
 );

 // Encoder
 SDObjectEncoder encoder = new SDObjectEncoder();

 // Encode
 Map<String, Object> encodedMap = encoder.encode(originalMap);

 // Disclosures yielded as a result of the encoding process.
 List<Disclosure> disclosures = encoder.getDisclosures();

 // Encoded dataset
 //
 //   {
 //     "key-2": [
 //       { "...": "Z_JV6E3FColTFBqUrvfa366V27BFy8cf8fa59NQdavg" },
 //       { "...": "p-vA6nPBgbL-Zgzd5MkVV7RrFPvMCV_f0N9p3CKOLVo" },
 //       { "...": "NVpowlkRQq9aC8aJAS3tz7Gzs3PolUJ7bZLYZiUg5pw" },
 //       { "...": "TfdBAy9CRDAhoyB2O3tcGUWOKnfSzQ1wKDTwJQyuFVU" },
 //       { "...": "Ujg9QqkNQ0tKN_DiPoCQOmHAWGThokrjA5ceve6Xxik" }
 //     ],
 //     "key-3": {
 //       "_sd": [
 //         "JVWbh08VUtBXLWOH16OgPMFZu7qGmKIc7Gt0dxwJin0",
 //         "YJ_T7R1qZsfdDIKoHFQ1ubOToI-DHZHBvZwBU6S1svE",
 //         "Z14X_kICU8SpDGpfDQ2mP1LfWAMtdPPRPJ_434cdKe4",
 //         "r67vz8Rq22eoCw_D-xDVa1bRucngVuRAExSQvWdbrXo"
 //       ]
 //     },
 //     "_sd": [
 //       "--3D5V1QiCzfs7gt4hxlaiFh02bBcUKH6VKCxAcPuGk",
 //       "ON2rSnqtfmLcJTrKKP5_l6swD3AkMbcmjb80hge2eMs",
 //       "wf2OtpIlIqG58GfXN6-jiDX-k1Wt4eJX-nPWbTdfonM"
 //     ],
 //     "_sd_alg": "sha-256"
 //   }
 //
 // Disclosures
 //
 //   | digest                                      | claim name | claim value  |
 //   |---------------------------------------------|------------|--------------|
 //   | ON2rSnqtfmLcJTrKKP5_l6swD3AkMbcmjb80hge2eMs | key-1      | value-1      |
 //   | NVpowlkRQq9aC8aJAS3tz7Gzs3PolUJ7bZLYZiUg5pw | (null)     | element-1    |
 //   | TfdBAy9CRDAhoyB2O3tcGUWOKnfSzQ1wKDTwJQyuFVU | (null)     | element-2    |
 //   | r67vz8Rq22eoCw_D-xDVa1bRucngVuRAExSQvWdbrXo | sub-key-1  | sub-value-1  |
 //   | Z14X_kICU8SpDGpfDQ2mP1LfWAMtdPPRPJ_434cdKe4 | sub-key-2  | sub-value-2  |
 //
 
Since:
1.3