package com.webank.weid.service.impl;
import com.networknt.schema.ValidationMessage;
import com.webank.wedpr.common.Utils;
import com.webank.wedpr.selectivedisclosure.*;
import com.webank.wedpr.selectivedisclosure.proto.Predicate;
import com.webank.wedpr.selectivedisclosure.proto.VerificationRule;
import com.webank.weid.constant.*;
import com.webank.weid.constant.CredentialConstant.CredentialProofType;
import com.webank.weid.exception.DataTypeCastException;
import com.webank.weid.exception.WeIdBaseException;
import com.webank.weid.protocol.base.*;
import com.webank.weid.protocol.cpt.Cpt101;
import com.webank.weid.protocol.cpt.Cpt111;
import com.webank.weid.protocol.request.CreateCredentialPojoArgs;
import com.webank.weid.protocol.response.ResponseData;
import com.webank.weid.service.rpc.CptService;
import com.webank.weid.service.rpc.CredentialPojoService;
import com.webank.weid.service.rpc.WeIdService;
import com.webank.weid.suite.persistence.PersistenceFactory;
import com.webank.weid.suite.persistence.Persistence;
import com.webank.weid.suite.persistence.PersistenceType;
import com.webank.weid.util.*;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;
/**
* Service implementations for operations on CredentialPojo.
*
* @author tonychen 2019年4月17日
*/
public class CredentialPojoServiceImpl implements CredentialPojoService {
private static final Logger logger = LoggerFactory.getLogger(CredentialPojoServiceImpl.class);
private static final String NOT_DISCLOSED =
CredentialFieldDisclosureValue.NOT_DISCLOSED.getStatus().toString();
private static final String DISCLOSED =
CredentialFieldDisclosureValue.DISCLOSED.getStatus().toString();
private static final String EXISTED =
CredentialFieldDisclosureValue.EXISTED.getStatus().toString();
private static WeIdService weIdService;
private static CptService cptService;
private static Persistence dataDriver;
private static PersistenceType persistenceType;
//private static PdfTransportation pdfTransportation;
private static Persistence getDataDriver() {
String type = PropertyUtils.getProperty("persistence_type");
if (type.equals("mysql")) {
persistenceType = PersistenceType.Mysql;
} else if (type.equals("redis")) {
persistenceType = PersistenceType.Redis;
}
if (dataDriver == null) {
dataDriver = PersistenceFactory.build(persistenceType);
}
return dataDriver;
}
private static WeIdService getWeIdService() {
if (weIdService == null) {
weIdService = new WeIdServiceImpl();
}
return weIdService;
}
private static CptService getCptService() {
if (cptService == null) {
cptService = new CptServiceImpl();
}
return cptService;
}
/*private static PdfTransportation getPdfTransportation() {
if (pdfTransportation == null) {
pdfTransportation = new PdfTransportationImpl();
}
return pdfTransportation;
}*/
/**
* Salt generator. Automatically fillin the map structure in a recursive manner.
*
* @param map the passed map (claim, salt or alike)
* @param fixed fixed value if required to use
*/
public static void generateSalt(Map<String, Object> map, Object fixed) {
for (Map.Entry<String, Object> entry : map.entrySet()) {
Object value = entry.getValue();
if (value instanceof Map) {
generateSalt((HashMap) value, fixed);
} else if (value instanceof List) {
boolean isMapOrList = generateSaltFromList((ArrayList<Object>) value, fixed);
if (!isMapOrList) {
if (fixed == null) {
addSalt(entry);
} else {
entry.setValue(fixed);
}
}
} else {
if (fixed == null) {
addSalt(entry);
} else {
entry.setValue(fixed);
}
}
}
}
private static void addSalt(Map.Entry<String, Object> entry) {
String salt = DataToolUtils.getRandomSalt();
entry.setValue(salt);
}
private static boolean generateSaltFromList(List<Object> objList, Object fixed) {
List<Object> list = (List<Object>) objList;
for (Object obj : list) {
if (obj instanceof Map) {
generateSalt((HashMap) obj, fixed);
} else if (obj instanceof List) {
boolean result = generateSaltFromList((ArrayList<Object>) obj, fixed);
if (!result) {
return result;
}
} else {
return false;
}
}
return true;
}
/**
* 校验claim、salt和disclosureMap的格式是否一致.
*/
private static boolean validCredentialMapArgs(Map<String, Object> claim,
Map<String, Object> salt, Map<String, Object> disclosureMap) {
//检查是否为空
if (claim == null || salt == null || disclosureMap == null) {
return false;
}
//检查每个map里的key个数是否相同
if (!claim.keySet().equals(salt.keySet())) {
return false;
}
//检查key值是否一致
for (Map.Entry<String, Object> entry : disclosureMap.entrySet()) {
String k = entry.getKey();
Object v = entry.getValue();
//如果disclosureMap中的key在claim中没有则返回false
if (!claim.containsKey(k)) {
return false;
}
Object saltV = salt.get(k);
Object claimV = claim.get(k);
if (v instanceof Map) {
//递归检查
if (!validCredentialMapArgs((HashMap) claimV, (HashMap) saltV, (HashMap) v)) {
return false;
}
} else if (v instanceof List) {
if (!validCredentialListArgs(
(ArrayList<Object>) claimV,
(ArrayList<Object>) saltV,
(ArrayList<Object>) v
)) {
return false;
}
}
}
return true;
}
private static boolean validCredentialListArgs(
List<Object> claimList,
List<Object> saltList,
List<Object> disclosureList) {
//检查是否为空
if (claimList == null || saltList == null || disclosureList == null) {
return false;
}
if (claimList.size() != saltList.size()) {
return false;
}
for (int i = 0; i < disclosureList.size(); i++) {
Object disclosureObj = disclosureList.get(i);
Object claimObj = claimList.get(i);
Object saltObj = saltList.get(i);
if (disclosureObj instanceof Map) {
boolean result =
validCredentialListArgs(
claimList,
saltList,
(HashMap) disclosureObj
);
if (!result) {
return result;
}
} else if (disclosureObj instanceof List) {
boolean result =
validCredentialListArgs(
(ArrayList<Object>) claimObj,
(ArrayList<Object>) saltObj,
(ArrayList<Object>) disclosureObj
);
if (!result) {
return result;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
WeIdentity-develop.zip (367个子文件)
.all-contributorsrc 6KB
make.bat 752B
make.bat 752B
run.config 1008B
gmsdk.crt 2KB
gmsdk.crt 2KB
sdk.crt 2KB
ca.crt 1KB
sdk.crt 1KB
gmca.crt 672B
gmca.crt 672B
gmensdk.crt 583B
gmensdk.crt 583B
ca.crt 0B
.gitattributes 405B
.gitignore 3KB
.gitkeep 70B
build.gradle 13KB
settings.gradle 73B
gradlew 6KB
hash 66B
main.iml 950B
sample.iml 423B
WeDPR-Java-SDK.jar 981KB
gradle-wrapper.jar 54KB
WeDPR-ecies.jar 5KB
CredentialPojoServiceImpl.java 101KB
DataToolUtils.java 53KB
TestCreateCredentialPojo.java 45KB
TestRegisterAuthorityIssuer.java 45KB
WeIdServiceImpl.java 41KB
CredentialPojoUtils.java 39KB
EvidenceServiceImpl.java 38KB
TestCreateEvidence.java 35KB
TestCreateSelectiveCredential.java 35KB
Base64.java 33KB
AuthorityIssuerServiceImpl.java 30KB
TestBaseUtil.java 26KB
Base32.java 26KB
CredentialServiceImpl.java 26KB
ErrorCode.java 25KB
TestBaseService.java 24KB
JsonUtil.java 24KB
TestCreatePresentation.java 23KB
TestVerifyCredentialByPublicKey.java 23KB
CptServiceImpl.java 22KB
TestCreateCredential.java 22KB
TestRegisterCptArgsWithId.java 22KB
TestVerifyCredential.java 21KB
TestRegisterCptArgs.java 21KB
TestVerifyCredentialByIssuer.java 21KB
TestUpdateCpt.java 20KB
TestSetAuthentication.java 20KB
BaseNCodec.java 19KB
CredentialUtils.java 18KB
TestRemoveAuthorityIssuer.java 16KB
TimestampUtils.java 16KB
Multicodec.java 15KB
TestCreateWeId2.java 15KB
TestRegisterCptStringArgsWithId.java 13KB
SqlExecutor.java 13KB
TestAddIssuerIntoIssuerType.java 13KB
PolicyServiceImpl.java 13KB
TestSetService.java 12KB
MysqlDriver.java 12KB
TestMysqlAdd.java 12KB
TestRedisAdd.java 12KB
HttpClient.java 11KB
RawCptSchema.java 11KB
TestRegisterCptStringArgs.java 10KB
BeanUtil.java 10KB
TestRegisterIssuerType.java 10KB
TestGetWeIdDocument.java 10KB
RedisDriver.java 10KB
WeIdUtils.java 9KB
ConnectionPool.java 9KB
TestDataTypetUtils.java 9KB
TestBaseTransportation.java 9KB
CredentialPojo.java 9KB
EvidenceService.java 9KB
BatchTransactionUtils.java 9KB
RedisExecutor.java 9KB
TestRemoveIssuerFromIssuerType.java 9KB
DataDriverConstant.java 9KB
DateUtils.java 8KB
TestIsAuthorityIssuer.java 8KB
WeIdConstant.java 8KB
TestVerifyCredentialWithPresentation.java 8KB
TestQueryAuthorityIssuerInfo.java 7KB
CredentialPojoService.java 7KB
TestGetAllAuthorityIssuerList.java 7KB
VarInt.java 7KB
PresentationE.java 7KB
TestMysqlUpdate.java 7KB
TestGetWeIdDocumentJson.java 7KB
MockMysqlDriver.java 7KB
Base58.java 7KB
PresentationPolicyE.java 7KB
TestVerifyCredentialWithSpecifiedPubKey.java 6KB
Cpt108.java 6KB
共 367 条
- 1
- 2
- 3
- 4
资源评论
m0_72731342
- 粉丝: 4
- 资源: 1829
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功