001package com.nimbusds.jose.crypto; 002 003 004import org.bouncycastle.jce.provider.BouncyCastleProvider; 005 006 007/** 008 * BouncyCastle provider singleton. Intended to guard against memory leaks. All 009 * JOSE+JWT code that makes use of BouncyCastle's JCE provider must use this 010 * singleton class to obtain an instance. 011 * 012 * @author Vladimir Dzhuvinov 013 */ 014public final class BouncyCastleProviderSingleton { 015 016 017 /** 018 * The BouncyCastle provider, lazily instantiated. 019 */ 020 private static BouncyCastleProvider bouncyCastleProvider; 021 022 023 /** 024 * Prevents external instantiation. 025 */ 026 private BouncyCastleProviderSingleton() { } 027 028 029 /** 030 * Returns a BouncyCastle provider instance. 031 * 032 * @return The BouncyCastle provider instance. 033 */ 034 public static BouncyCastleProvider getInstance() { 035 036 if (bouncyCastleProvider != null) { 037 038 return bouncyCastleProvider; 039 040 } else { 041 bouncyCastleProvider = new BouncyCastleProvider(); 042 return bouncyCastleProvider; 043 } 044 } 045}